malcommac / SwiftDate

🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
MIT License
7.64k stars 768 forks source link

Incorrect weekday Int value for non-Sunday start of week #826

Open andy3a1 opened 3 months ago

andy3a1 commented 3 months ago

by default different Calendar.Identifier values have different Calendar.current.firstWeekday. Also there is a possibility to choose any day as start of week in Settings.

image

Suggesting to change this code

var weekday: Int { return dateComponents.weekday! }

by adding dependency on Calendar.current.firstWeekday

var weekday: Int { return (dateComponents.weekday! - Calendar.current.firstWeekday + 7) % 7 + 1 }