JTCalendar
JTCalendar copied to clipboard
Start of the week not changing
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.
@jonathantribouharet Do you have a solution for this? It doesn't work for me either.
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];
@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()
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.
@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?
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.
For me it worked when I changed the firstWeekday
property of the NSCalendar instance.
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()
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