JTCalendar icon indicating copy to clipboard operation
JTCalendar copied to clipboard

Start of the week not changing

Open shravansukumar opened this issue 7 years ago • 9 comments

I'm displaying a month view and by default, the week starts from sunday. I'd like to change this to be monday. I'm doing this by:

        var startOfWeek = calendarManager.dateHelper.calendar()
        startOfWeek?.firstWeekday = 2

But this doesn't seem to work. Any help would be appreciated.

shravansukumar avatar Aug 24 '17 07:08 shravansukumar

@jonathantribouharet Do you have a solution for this? It doesn't work for me either.

kishykumar avatar Oct 22 '17 22:10 kishykumar

Yes, this attribute doesn't work (don't know why), you have to use the timezone and locale.

_calendarManager.dateHelper.calendar.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"CDT"];
_calendarManager.dateHelper.calendar.locale = [NSLocale localeWithLocaleIdentifier:@"fr_FR"];
[_calendarManager reload];

johnvuko avatar Oct 23 '17 07:10 johnvuko

@jonathantribouharet this doesn't work either. Here is my code:

    self.calendarManager = JTCalendarManager()
    self.calendarManager.delegate = self
    self.calendarManager.menuView = calendarMenuOutlet
    self.calendarManager.contentView = calendarOutlet
    self.calendarManager.setDate(Date())
    
    var calendar = self.calendarManager.dateHelper.calendar()
    calendar!.locale = Locale(identifier: "fr_FR")
    calendar!.timeZone = TimeZone.init(abbreviation: "CDT")!
    calendar!.firstWeekday = 4 // Wednesday
    
    computeStartEndWeek(Date())
    self.calendarManager.reload()

kishykumar avatar Oct 25 '17 05:10 kishykumar

Sorry, I wasn't clear, the attribute firstWeekday never worked (for me). So I don't know how to set a chosen firstWeekday manually. In general, when you want to change the firstWeekday it's because you want your users to have the right first weekday depending of where they live so it's more simple to change the timezone by the timezone of your user which work.

johnvuko avatar Oct 25 '17 10:10 johnvuko

@jonathantribouharet I have a different use case. I am showing the weekly earnings for the service providers for 7 days from Wednesday to Tuesday. So, I want to show Wednesday as the first week day. Do you know of any way to achieve this?

kishykumar avatar Oct 31 '17 08:10 kishykumar

The code managing this is here. I didn't find how to do it before, baybe it's just an option missing, if you find it I will update the lib.

johnvuko avatar Oct 31 '17 11:10 johnvuko

For me it worked when I changed the firstWeekday property of the NSCalendar instance.

ph1lb4 avatar Feb 04 '19 12:02 ph1lb4

Swift :

Set your timezone and localisation while initialise calendar.

calendarManager = JTCalendarManager.init(locale: Locale(identifier: "en"), andTimeZone: TimeZone.current)
calendarManager!.delegate = self
calendarManager!.settings.weekDayFormat = .single;
calendarManager!.reload()

rajesh-loganathan avatar Feb 13 '19 08:02 rajesh-loganathan

Hi, This can be fixed easily if we add one setting method in JTDateHelper.

  • (void) setFirstDayOfWeek:(int) day { weekStartDay = day; } I am currently using this in my code. But i have to write this separately as it is not present in github code. Can we add it in m ain code. I have tested it is working if someone wants to have different week start day irrespective of their timezone. @jonathantribouharet

ghost avatar Jun 22 '21 07:06 ghost