Skip to content

Commit

Permalink
fix calender
Browse files Browse the repository at this point in the history
  • Loading branch information
1amageek committed Apr 11, 2016
1 parent bced1d4 commit 3fee77c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion PHFetchedResultsController.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "PHFetchedResultsController"
s.version = "2.1.0"
s.version = "2.1.1"
s.summary = "A fetchedResultsController for PhotoKit. It can be divided into sections by date PhotoKit"
s.homepage = "https://github.com/1amageek/PHFetchedResultsController"
#s.screenshots = ""
Expand Down
20 changes: 11 additions & 9 deletions PHFetchedResultsController/PHFetchedResultsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (instancetype)initWithAssetCollection:(PHAssetCollection *)assetCollection
{
self = [super init];
if (self) {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
_dateComponents = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfMonth | NSCalendarUnitDay | NSCalendarUnitHour fromDate:date];
_assetCollection = assetCollection;
_options = options;
Expand Down Expand Up @@ -95,8 +95,10 @@ - (NSString *)name
if (_name) {
return _name;
}
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateFormatter *dateFormatter = [self.delegate dateFormatter];
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:self.dateComponents];
dateFormatter.calendar = calendar;
NSDate *date = [calendar dateFromComponents:self.dateComponents];
_name = [dateFormatter stringFromDate:date];
return _name;
}
Expand Down Expand Up @@ -134,15 +136,15 @@ - (NSUInteger)numberOfObjects
NSDateComponents *addDateComponents = [NSDateComponents new];
NSDate *startDate;
NSDate *endDate;
NSCalendar *calendar = [NSCalendar currentCalendar];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
switch (sectionKey) {
case PHFetchedResultsSectionKeyHour: {
[dateComponents setYear:self.year];
[dateComponents setMonth:self.month];
[dateComponents setWeekOfMonth:self.week];
[dateComponents setDay:self.day];
[dateComponents setHour:self.hour];
startDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
startDate = [calendar dateFromComponents:dateComponents];
[addDateComponents setHour:1];
endDate = [calendar dateByAddingComponents:addDateComponents toDate:startDate options:0];
}
Expand All @@ -152,7 +154,7 @@ - (NSUInteger)numberOfObjects
[dateComponents setMonth:self.month];
[dateComponents setWeekOfMonth:self.week];
[dateComponents setDay:self.day];
startDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
startDate = [calendar dateFromComponents:dateComponents];
[addDateComponents setDay:1];
endDate = [calendar dateByAddingComponents:addDateComponents toDate:startDate options:0];
}
Expand All @@ -162,15 +164,15 @@ - (NSUInteger)numberOfObjects
[dateComponents setMonth:self.month];
[dateComponents setWeekOfMonth:self.week];
[dateComponents setWeekday:1];
startDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
startDate = [calendar dateFromComponents:dateComponents];
[addDateComponents setWeekOfMonth:1];
endDate = [calendar dateByAddingComponents:addDateComponents toDate:startDate options:0];
}
break;
case PHFetchedResultsSectionKeyMonth: {
[dateComponents setYear:self.year];
[dateComponents setMonth:self.month];
startDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
startDate = [calendar dateFromComponents:dateComponents];
[addDateComponents setMonth:1];
endDate = [calendar dateByAddingComponents:addDateComponents toDate:startDate options:0];
}
Expand Down Expand Up @@ -477,7 +479,7 @@ - (_PHFetchTask *)findSectionInfoInAssets:(NSArray<PHAsset *> *)assets

// NSMutableArray *sections = [NSMutableArray array];

__block NSCalendar *calendar = [NSCalendar currentCalendar];
__block NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
__block NSInteger previousYear = 0;
__block NSInteger previousMonth = 0;
__block NSInteger previousWeek = 0;
Expand Down Expand Up @@ -601,7 +603,7 @@ - (PHAsset *)assetAtIndexPath:(NSIndexPath *)indexPath

- (NSIndexPath *)indexPathForAsset:(PHAsset *)asset
{
NSCalendar *calendar = [NSCalendar currentCalendar];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *dateComponets = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfMonth | NSCalendarUnitDay | NSCalendarUnitHour fromDate:asset.creationDate];

NSInteger year = [dateComponets year];
Expand Down
2 changes: 1 addition & 1 deletion PHFetchedResultsController/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (PHFetchedResultsController *)fetchedResultsController

_fetchedResultsController = [[PHFetchedResultsController alloc] initWithAssetCollection:assetCollection sectionKey:PHFetchedResultsSectionKeyWeek mediaType:PHFetchedResultsMediaTypeImage ignoreLocalIDs:@[]];
_fetchedResultsController.delegate = self;
_fetchedResultsController.dateFormateForSectionTitle = @"yyyy.MM.DD";
_fetchedResultsController.dateFormateForSectionTitle = @"yyyy.MM.dd";

[_fetchedResultsController performFetch:nil];

Expand Down

0 comments on commit 3fee77c

Please sign in to comment.