Skip to content

.offset(.day, value: d) does not work for all days of the week #127

Open

Description

@vince-marco

My code:

var weekdays: [Date] {
var days = Date
let sunday = Date.now.adjust(for: .startOfWeek)!
for d in 0...6 {
let day = sunday.offset(.day, value: d)!
days.append(day)
}
return days
}

Results in:

Sun - 6/2/24, 12:00 AM
Mon - 6/3/24, 12:00 AM
Tue - 6/4/24, 12:00 AM
Wed - 6/5/24, 12:00 AM
Tue - 6/4/24, 12:00 AM
Fri - 6/7/24, 12:00 AM
Sun - 6/2/24, 12:00 AM

Thursday Saturday are wrong!

Activity

  1. vince-marco commented on Jun 8, 2024

    @vince-marco
    Author

    This is possibly an issue with Apple's Date class, as it produces the same results with .addingTimeInterval(606024).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions