mattt/CupertinoYankee — pull request #2 by nvln (2013-10-15 22:41:03+00:00)
Title: Take NSCalendar -firstWeekday into account in -beginningOfWeek

Both -beginningOfWeek and -testBeginningOfWeek assume that the first day of the week is Monday, which I think is wrong.

The first day of the week is defined by NSCalendar's -firstWeekday property. This is usually a Sunday (firstWeekday == 1) or Monday (firstWeekday == 2) depending on the locale. (Plus it can, at least in theory, be arbitrarily set to any other week day.)

I've changed the offset calculation in -beginningOfWeek to be fully based on NSCalendar's -firstWeekday. That way the beginning of the week will be whatever NSCalendar's -firstWeekday is.

I've added a test that checks whether a date returned by -beginningOfWeek has it's weekday component equal to NSCalendar's -firstWeekday. My commits break -beginningOfWeekTests and -endOfWeekTests. I'll happily rewrite those once we agree that my fix makes sense.