melvitax / DateHelper

A Swift Date extension helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Start of week on Monday instead of Sunday

EverCodeAP opened this issue · comments

I'd like to call dateFor(.startOfWeek) and get Monday's date instead of Sunday's. Same thing with .endOfWeek - Sunday instead of Saturday.
Is there any way to configure this library this way or is it completely dependent on phone settings or something?

This function now uses a calendar's start of week to calculate the start of the week. You can pass it a custom calendar that has this setting or rely on the current user's calendar setting.

var calendar = Calendar(identifier: .gregorian) calendar = 2 // sets the week to start on the second day.. Monday now.dateFor(.startOfWeek, calendar: calendar)