ios - `weekday` 是否保证在 [1:7] 范围内?
问题描述
我相信答案是肯定的,但 Apple 的文档暗示答案是否定的。
工作日单位是数字 1 到 n,其中 n 是一周中的天数。例如,在公历中,n 为 7,星期日由 1 表示。weekday
这句话似乎表明不同的日历系统有不同的周长。在对 Wikipedia 进行一些研究后,我找不到任何现代日历在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")
}
}
}
推荐阅读
- mysql - 动态创建表并将数据从 MySQL 复制到 SQL Server 数据库
- sql - 'CASE' 表达式是否将 WHERE 条件应用于查询
- python - 如何按文件名重新组织大量文件?
- laravel - barryvdh / laravel-dompdf,Laravel 6,在 Chrome、Android 上没有响应
- swift - Swift:父/子关系的 Init() 模式
- pycharm - opencv-python(V4.2.0.32) imread 代码在 python 中不起作用(pycharm for win)
- c# - 从信号器集线器调用 Web Api 方法
- react-native - 如何像在 vsCode 中一样在 webstorm 中进行自动完成以响应本机?
- android - 通过按下硬件按钮启动 android 应用程序
- java - 我们可以使用 Any Join 删除表中的重复行吗?