Skip to content

Commit

Permalink
Change [JTCalendarManager init] to accept locale and timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
ilaszlo committed Feb 1, 2018
1 parent 8be2473 commit 3fac861
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Example/Example/CustomViewController.m
Expand Up @@ -33,15 +33,14 @@ - (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
[self createRandomEvents];

_calendarMenuView.contentRatio = .75;
_calendarManager.settings.weekDayFormat = JTCalendarWeekDayFormatSingle;
_calendarManager.dateHelper.calendar.locale = [NSLocale localeWithLocaleIdentifier:@"fr_FR"];

[_calendarManager setMenuView:_calendarMenuView];
[_calendarManager setContentView:_calendarContentView];
Expand Down
3 changes: 1 addition & 2 deletions JTCalendar/JTCalendarManager.h
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions JTCalendar/JTCalendarManager.m
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions JTCalendar/JTDateHelper.h
Expand Up @@ -9,6 +9,8 @@

@interface JTDateHelper : NSObject

- initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone;

- (NSCalendar *)calendar;
- (NSDateFormatter *)createDateFormatter;

Expand Down
16 changes: 14 additions & 2 deletions JTCalendar/JTDateHelper.m
Expand Up @@ -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){
Expand All @@ -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;
Expand Down

0 comments on commit 3fac861

Please sign in to comment.