| | |
| | | + (instancetype)fromDate:(NSDate *)date |
| | | { |
| | | Solar *solar = [Solar fromDate:date]; |
| | | return [self fromSolar:solar]; |
| | | } |
| | | |
| | | + (instancetype)fromSolar:(Solar *)solar |
| | | { |
| | | NSInteger y = solar.year; |
| | | NSInteger m = solar.month; |
| | | NSInteger d = solar.day; |
| | |
| | | NSInteger startYear = [SolarUtil share].BASE_YEAR + 99; |
| | | NSInteger startMonth = 1; |
| | | NSInteger startDay = 1; |
| | | |
| | | NSInteger lunarYear = [LunarUtil share].BASE_YEAR + 99; |
| | | NSInteger lunarMonth = 11; |
| | | NSInteger lunarDay = 25; |
| | | |
| | | if (y < 2000) { |
| | | startYear = [SolarUtil share].BASE_YEAR; |
| | | startMonth = [SolarUtil share].BASE_MONTH; |
| | | startDay = [SolarUtil share].BASE_DAY; |
| | | lunarYear = [LunarUtil share].BASE_YEAR; |
| | | lunarMonth = [LunarUtil share].BASE_MONTH; |
| | | lunarDay = [LunarUtil share].BASE_DAY; |
| | | startYear = [SolarUtil share].BASE_YEAR; |
| | | startMonth = [SolarUtil share].BASE_MONTH; |
| | | startDay = [SolarUtil share].BASE_DAY; |
| | | |
| | | lunarYear = [LunarUtil share].BASE_YEAR; |
| | | lunarMonth = [LunarUtil share].BASE_MONTH; |
| | | lunarDay = [LunarUtil share].BASE_DAY; |
| | | } |
| | | |
| | | NSInteger diff = 0; |
| | |
| | | NSInteger d = 30; |
| | | |
| | | if (1 <= month && month <= 8) { |
| | | |
| | | if (2*index >= [LunarUtil share].LUNAR_MONTH.count) { |
| | | NSLog(@"getDaysOfMonth 数组越界:%@", @(month)); |
| | | return d; |
| | | } |
| | | |
| | | NSInteger v = [[LunarUtil share].LUNAR_MONTH[2*index] integerValue]; |
| | | NSInteger l = month - 1; |
| | | if (((v >> l) & 0x01) == 1) { |
| | | d = 29; |
| | | } |
| | | } else if (9 <= month && month <= 12) { |
| | | |
| | | if (2*index >= [LunarUtil share].LUNAR_MONTH.count) { |
| | | NSLog(@"getDaysOfMonth 数组越界:%@", @(month)); |
| | | return d; |
| | | } |
| | | |
| | | NSInteger v = [[LunarUtil share].LUNAR_MONTH[2*index+1] integerValue]; |
| | | NSInteger l = month - 9; |
| | | if (((v >> l) & 0x01) == 1) { |
| | | d = 29; |
| | | } |
| | | } else { |
| | | |
| | | if (2*index+1 >= [LunarUtil share].LUNAR_MONTH.count) { |
| | | NSLog(@"getDaysOfMonth 数组越界:%@", @(month)); |
| | | return d; |
| | | } |
| | | |
| | | NSInteger v = [[LunarUtil share].LUNAR_MONTH[2*index+1] integerValue]; |
| | | v = (v >> 4) & 0x0F; |
| | | if (v != labs(month)) { |
| | |
| | | + (NSInteger)getLeapMonth:(NSInteger)year |
| | | { |
| | | NSInteger index = year - [LunarUtil share].BASE_YEAR + [LunarUtil share].BASE_INDEX; |
| | | NSInteger v = [[LunarUtil share].LUNAR_MONTH[2*index + 1] integerValue]; |
| | | |
| | | if (2*index+1 >= [LunarUtil share].LUNAR_MONTH.count) { |
| | | NSLog(@"getLeapMonth 数组越界:%@", @(year)); |
| | | return 0; |
| | | } |
| | | |
| | | NSInteger v = [[LunarUtil share].LUNAR_MONTH[2*index+1] integerValue]; |
| | | v = (v >> 4) & 0x0F; |
| | | return v; |
| | | } |
| | |
| | | |
| | | - (Lunar *)getLunar |
| | | { |
| | | return [Lunar fromDate:_calendar]; |
| | | return [Lunar fromSolar:self]; |
| | | } |
| | | |
| | | /** |