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

标签 ios date calendar foundation

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

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/

相关文章:

ios - iPhone 连接到 localhost Rails sarver

java - 为什么 Java 的 Date.after() 在日期实际上更早时返回 'true'?

java - 如何检查日期是否已经超过列表中的日期?在java中

jquery - 在输入点击和附加图标上触发 jQuery datepicker 元素

api - 是否有包含全局公共(public)/银行假日的综合 API 或 JSON/XML 列表?

javascript - HTML:iCal 链接?

ios - 如何手动弃用成员

javascript - Cordova 中从 arraybuffer 到 blob

iphone - IOS程序如何存放数据库

Python格式化Ctime方法