Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to inject custom calendar with backward compatibility #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions JTCalendar/JTCalendarManager.h
Expand Up @@ -34,6 +34,7 @@
@property (nonatomic, readonly) JTCalendarScrollManager * _Nullable scrollManager;

- (instancetype _Nullable )initWithLocale:(NSLocale *_Nullable)locale andTimeZone:(NSTimeZone *_Nullable)timeZone;
- (instancetype _Nullable )initWithCalendar:(NSCalendar *_Nonnull)calendar;

- (NSDate *_Nonnull)date;
- (void)setDate:(NSDate *_Nullable)date;
Expand Down
17 changes: 16 additions & 1 deletion JTCalendar/JTCalendarManager.m
Expand Up @@ -27,9 +27,24 @@ - (instancetype)initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)time
return self;
}

- (instancetype)initWithCalendar:(NSCalendar*)calendar
{
self = [super init];
if(!self){
return nil;
}

_dateHelper = [[JTDateHelper alloc] initWithCalendar:calendar];
[self commonInit:calendar.locale andTimeZone:calendar.timeZone];

return self;
}

- (void)commonInit:(NSLocale *)locale andTimeZone:(NSTimeZone *)timeZone
{
_dateHelper = [[JTDateHelper alloc] initWithLocale:locale andTimeZone:timeZone];
if (_dateHelper == nil){
_dateHelper = [[JTDateHelper alloc] initWithLocale:locale andTimeZone:timeZone];
}
_settings = [JTCalendarSettings new];

_delegateManager = [JTCalendarDelegateManager new];
Expand Down
1 change: 1 addition & 0 deletions JTCalendar/JTDateHelper.h
Expand Up @@ -10,6 +10,7 @@
@interface JTDateHelper : NSObject

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

- (NSCalendar *)calendar;
- (NSDateFormatter *)createDateFormatter;
Expand Down
11 changes: 11 additions & 0 deletions JTCalendar/JTDateHelper.m
Expand Up @@ -27,6 +27,17 @@ - (instancetype)initWithLocale:(NSLocale *)locale andTimeZone:(NSTimeZone *)time
return self;
}

- (instancetype)initWithCalendar:(NSCalendar *)calendar
{
self = [super init];
if (self) {
_calendar = calendar;
_locale = calendar.locale;
_timeZone = calendar.timeZone;
}
return self;
}

- (NSCalendar *)calendar
{
if(!_calendar){
Expand Down