gpt4 book ai didi

ios - `weekday` 是否保证在范围 [1 :7]?

转载 作者:行者123 更新时间:2023-11-28 23:27:28 26 4
gpt4 key购买 nike

我相信答案是肯定的,但苹果的文档暗示答案是否定的。

Weekday units are the numbers 1 through n, where n is the number of days in the week. For example, in the Gregorian calendar, n is 7 and Sunday is represented by 1. weekday

这句话似乎表明不同日历系统有不同的周长度。在对维基百科进行一些研究后,我找不到任何 n != 7 的现代日历。

我是不是看错了? Foundation 中是否有日历中的周数为 n != 7

最佳答案

这不一定是保证,但以下代码找不到除 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")
}
}
}

关于ios - `weekday` 是否保证在范围 [1 :7]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58174444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com