From 3fac861ade0551dc3f069dcf9a696386fa8ec57a Mon Sep 17 00:00:00 2001 From: Ilonka Laszlo Date: Thu, 1 Feb 2018 09:22:47 +0100 Subject: [PATCH] Change [JTCalendarManager init] to accept locale and timezone --- Example/Example/CustomViewController.m | 3 +-- JTCalendar/JTCalendarManager.h | 3 +-- JTCalendar/JTCalendarManager.m | 12 ++++++++---- JTCalendar/JTDateHelper.h | 2 ++ JTCalendar/JTDateHelper.m | 16 ++++++++++++++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Example/Example/CustomViewController.m b/Example/Example/CustomViewController.m index 21c4a41..1f68f7f 100644 --- a/Example/Example/CustomViewController.m +++ b/Example/Example/CustomViewController.m @@ -33,7 +33,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - _calendarManager = [JTCalendarManager new]; + _calendarManager = [[JTCalendarManager alloc] initWithLocale:[NSLocale localeWithLocaleIdentifier:@"fr_FR"] andTimeZone:[NSTimeZone localTimeZone]]; _calendarManager.delegate = self; // Generate random events sort by date using a dateformatter for the demonstration @@ -41,7 +41,6 @@ - (void)viewDidLoad _calendarMenuView.contentRatio = .75; _calendarManager.settings.weekDayFormat = JTCalendarWeekDayFormatSingle; - _calendarManager.dateHelper.calendar.locale = [NSLocale localeWithLocaleIdentifier:@"fr_FR"]; [_calendarManager setMenuView:_calendarMenuView]; [_calendarManager setContentView:_calendarContentView]; diff --git a/JTCalendar/JTCalendarManager.h b/JTCalendar/JTCalendarManager.h index de5624e..a5f8508 100644 --- a/JTCalendar/JTCalendarManager.h +++ b/JTCalendar/JTCalendarManager.h @@ -33,8 +33,7 @@ @property (nonatomic, readonly) JTCalendarDelegateManager *delegateManager; @property (nonatomic, readonly) JTCalendarScrollManager *scrollManager; -// Use for override -- (void)commonInit; +- (instancetype)initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone; - (NSDate *)date; - (void)setDate:(NSDate *)date; diff --git a/JTCalendar/JTCalendarManager.m b/JTCalendar/JTCalendarManager.m index a85fee5..c826bc2 100644 --- a/JTCalendar/JTCalendarManager.m +++ b/JTCalendar/JTCalendarManager.m @@ -12,20 +12,24 @@ @implementation JTCalendarManager - (instancetype)init +{ + return [self initWithLocale:[NSLocale currentLocale] andTimeZone:[NSTimeZone localTimeZone]]; +} + +- (instancetype)initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone { self = [super init]; if(!self){ return nil; } - - [self commonInit]; + [self commonInit:locale andTimeZone:timeZone]; return self; } -- (void)commonInit +- (void)commonInit:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone { - _dateHelper = [JTDateHelper new]; + _dateHelper = [[JTDateHelper alloc] initWithLocale:locale andTimeZone:timeZone]; _settings = [JTCalendarSettings new]; _delegateManager = [JTCalendarDelegateManager new]; diff --git a/JTCalendar/JTDateHelper.h b/JTCalendar/JTDateHelper.h index 57d57af..81004bc 100644 --- a/JTCalendar/JTDateHelper.h +++ b/JTCalendar/JTDateHelper.h @@ -9,6 +9,8 @@ @interface JTDateHelper : NSObject +- initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone; + - (NSCalendar *)calendar; - (NSDateFormatter *)createDateFormatter; diff --git a/JTCalendar/JTDateHelper.m b/JTCalendar/JTDateHelper.m index b0f4932..f3702a4 100644 --- a/JTCalendar/JTDateHelper.m +++ b/JTCalendar/JTDateHelper.m @@ -9,12 +9,24 @@ @interface JTDateHelper (){ NSCalendar *_calendar; + NSLocale *_locale; + NSTimeZone *_timeZone; } @end @implementation JTDateHelper +- (instancetype)initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone +{ + self = [super init]; + if (self) { + _locale = locale; + _timeZone = timeZone; + } + return self; +} + - (NSCalendar *)calendar { if(!_calendar){ @@ -23,8 +35,8 @@ - (NSCalendar *)calendar #else _calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; #endif - _calendar.timeZone = [NSTimeZone localTimeZone]; - _calendar.locale = [NSLocale currentLocale]; + _calendar.timeZone = _timeZone; + _calendar.locale = _locale; } return _calendar;