19世紀にさかのぼるアプリの2つの異なる日付の間のうるう年の日数を決定しようとしています-これがメソッドの例です:
-(NSInteger)leapYearDaysWithinEraFromDate:(NSDate *) startingDate toDate:(NSDate *) endingDate {
// this is for testing - it will be changed to a datepicker object
NSDateComponents *startDateComp = [[NSDateComponents alloc] init];
[startDateComp setSecond:1];
[startDateComp setMinute:0];
[startDateComp setHour:1];
[startDateComp setDay:14];
[startDateComp setMonth:4];
[startDateComp setYear:2005];
NSCalendar *GregorianCal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
//startDate declared in .h//
startDate = [GregorianCal dateFromComponents:startDateComp];
NSLog(@"This program's start date is %@", startDate);
NSDate *today = [NSDate date];
NSUInteger unitFlags = NSDayCalendarUnit;
NSDateComponents *temporalDays = [GregorianCal components:unitFlags fromDate:startDate toDate:today options:0];
NSInteger days = [temporalDays day];
// then i will need code for the number of leap year Days
return 0;//will return the number of 2/29 days
}
したがって、日付間の合計日数があります。今、うるう年の日数を引く必要がありますか???
PS - この例ではうるう年が 2 日あることはわかっていますが、アプリは 19 世紀にさかのぼります...