[Suggestion] ISO standard weekday indexing
Is your feature request related to a problem? Please describe.
Most languages have dates indexed from Monday to Sunday (following iso standards). Swift's Calendar apis are indexed Sunday to Saturday.
Describe the solution you'd like
Most backwards compatible solution:
- add an isoWeekday property to DateComponents
Probably the more correct solution:
- when using an iso8601 calendar, weekdays should be indexed following iso standards
Additional context Add any other context about the feature request here.
It seems to be working as expected on main (and I believe in the 6.2 branch too since we haven't touched this after branching)
let first = Calendar(identifier: .iso8601).firstWeekday // 2
Which translates to Monday.
Is this not what you're seeing, or are you referring to other API?
Im referring to the fact that weekday mappings are as follows:
sunday - 1 monday - 2 Tuesday - 3 etc...
the ISO standard is:
monday - 1 Tuesday - 2 ... sunday - 7
I don't think we can ever change this without breaking existing clients. There are other API that requires this ordering, such as Calendar.weekdaySymbols, so the ordering is basically ABI stable and cannot be broken.
I don't think we can ever change this without breaking existing clients. There are other API that requires this ordering, such as
Calendar.weekdaySymbols, so the ordering is basically ABI stable and cannot be broken.
Can an additional property be added?
For example:
// new
DateComponents(isoWeekday: 1) // would produce a date on a Monday
// existing behavior
DateComponents(weekday: 1) // would produce a date on a Sunday.
This ensures backwards compatibility.
DateComponents has a Calendar variable, and the convention is to refer calendar related information to the calendar. Given that this information is available in Calendar, adding this similar property on DateComponents seems redundant
Also
let day = DateComponents(isoWeekday: 1) // would produce a date on a Monday
Can you spell it out for me? Would day be an integer or a enum or something that represents a Monday?