Skip to content

Commit

Permalink
Merge pull request WenchaoD#998 from drbill-github/master
Browse files Browse the repository at this point in the history
Ability to specify the timezone for the fscalendar.
  • Loading branch information
WenchaoD authored Feb 17, 2023
2 parents 76afe50 + f42f56e commit 2a1bdab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
5 changes: 5 additions & 0 deletions FSCalendar/FSCalendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ NS_ASSUME_NONNULL_BEGIN
IB_DESIGNABLE
@interface FSCalendar : UIView

/**
* The timezone of the calendar. `defaultTimeZone` by default.
*/
@property (strong, nonatomic) NSTimeZone *timeZone;

/**
* The object that acts as the delegate of the calendar.
*/
Expand Down
22 changes: 20 additions & 2 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ @interface FSCalendar ()<UICollectionViewDataSource,UICollectionViewDelegate,FSC

@property (strong, nonatomic) NSCalendar *gregorian;
@property (strong, nonatomic) NSDateFormatter *formatter;
@property (strong, nonatomic) NSTimeZone *timeZone;

@property (weak , nonatomic) UIView *contentView;
@property (weak , nonatomic) UIView *daysContainer;
Expand Down Expand Up @@ -280,6 +279,12 @@ - (void)setValue:(id)value forUndefinedKey:(NSString *)key

}

- (void)setTimeZone:(NSTimeZone *)tz
{
_timeZone = tz;
[self invalidateDateTools];
}

- (void)layoutSubviews
{
[super layoutSubviews];
Expand Down Expand Up @@ -701,7 +706,7 @@ - (void)setToday:(NSDate *)today
_today = nil;
} else {
FSCalendarAssertDateInBounds(today,self.gregorian,self.minimumDate,self.maximumDate);
_today = [self.gregorian startOfDayForDate:today];
[self updateToday];
}
if (self.hasValidateVisibleLayout) {
[self.visibleCells makeObjectsPerformSelector:@selector(setDateIsToday:) withObject:nil];
Expand Down Expand Up @@ -1272,6 +1277,19 @@ - (void)invalidateDateTools
_formatter.calendar = _gregorian;
_formatter.timeZone = _timeZone;
_formatter.locale = _locale;

[self updateToday];
}

- (void)updateToday
{
NSDateComponents *dateComponents = [self.gregorian components:(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay) fromDate:[NSDate date]];
dateComponents.hour = 0;
dateComponents.minute = 0;
dateComponents.second = 0;
dateComponents.timeZone = self.timeZone;

_today = [self.gregorian dateFromComponents:dateComponents];
}

- (void)invalidateLayout
Expand Down

0 comments on commit 2a1bdab

Please sign in to comment.