我相信答案是肯定的,但是Apple的文档暗示答案是否定的。
工作日单位是从1到n的数字,其中n是一周中的天数。例如,在阳历中,n为7,星期日由1表示。weekday
该报价似乎暗示着不同的日历系统还有其他周长。在对Wikipedia进行了一些研究之后,我找不到n != 7
所在的任何现代日历。
我误读了吗? Foundation中是否有n != 7
个星期的日历?
答案 0 :(得分:1)
这不一定是保证,但是以下代码找不到除1..<8
以外没有工作日范围的任何区域的日历。
let calIds: [Calendar.Identifier] = [ .buddhist, .chinese, .coptic, .ethiopicAmeteAlem, .ethiopicAmeteMihret, .gregorian, .hebrew, .indian, .islamic, .islamicCivil, .islamicTabular, .islamicUmmAlQura, .iso8601, .japanese, .persian, .republicOfChina]
for calId in calIds {
var cal = Calendar(identifier: calId)
for locId in Locale.availableIdentifiers {
let locale = Locale(identifier: locId)
cal.locale = locale
if let weekdayMin = cal.minimumRange(of: .weekday), let weekdayMax = cal.maximumRange(of: .weekday) {
if weekdayMin == weekdayMax {
if weekdayMin.startIndex != 1 || weekdayMin.count != 7 {
print("Calendar \(calId) with locale \(locId) isn't 1..<8: \(weekdayMin)")
}
} else {
print("Calendar \(calId) with locale \(locId) has a different min and max weekday range: \(weekdayMin) - \(weekdayMax)")
}
} else {
print("Calendar \(calId) with locale \(locId) doesn't have both a min and max weekday range")
}
}
}