| Lunar/Lunar.xcodeproj/project.pbxproj | ●●●●● patch | view | raw | blame | history | |
| Lunar/Lunar/Tool/Lunar.h | ●●●●● patch | view | raw | blame | history | |
| Lunar/Lunar/Tool/Lunar.m | ●●●●● patch | view | raw | blame | history | |
| Lunar/Lunar/ViewController.m | ●●●●● patch | view | raw | blame | history |
Lunar/Lunar.xcodeproj/project.pbxproj
@@ -42,6 +42,13 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 076D1B56261713D800087D45 /* Util */ = { isa = PBXGroup; children = ( ); path = Util; sourceTree = "<group>"; }; 07F51C1A2615C1A600D30158 = { isa = PBXGroup; children = ( @@ -86,6 +93,7 @@ 07F51C462615C33A00D30158 /* Tool */ = { isa = PBXGroup; children = ( 076D1B56261713D800087D45 /* Util */, 07F51C472615C34A00D30158 /* Lunar.h */, 07F51C482615C34A00D30158 /* Lunar.m */, ); Lunar/Lunar/Tool/Lunar.h
@@ -164,6 +164,7 @@ + (instancetype)fromYmd:(NSInteger)lunarYear :(NSInteger)lunarMonth :(NSInteger)lunarDay; + (instancetype)fromYmdHms:(NSInteger)lunarYear :(NSInteger)lunarMonth :(NSInteger)lunarDay :(NSInteger)hour :(NSInteger)minute :(NSInteger)second; + (instancetype)fromDate:(NSDate *)date; + (instancetype)fromSolar:(Solar *)solar; + (CGFloat)nutationLon2:(CGFloat)t; + (CGFloat)eLon:(CGFloat)t :(NSInteger)n; + (CGFloat)gxcSunLon:(CGFloat)t; @@ -411,8 +412,8 @@ @property (nonatomic, assign) NSInteger BASE_DAY_GAN_ZHI_INDEX; @property (nonatomic, assign) NSInteger BASE_MONTH_ZHI_INDEX; @property (nonatomic, assign) NSInteger BASE_WEEK_INDEX; @property (nonatomic, strong) NSArray *LEAP_MONTH_YEAR; @property (nonatomic, strong) NSArray *LUNAR_MONTH; @property (nonatomic, strong) NSArray *LEAP_MONTH_YEAR;// 闰年表 @property (nonatomic, strong) NSArray *LUNAR_MONTH;// 闰月表 @property (nonatomic, strong) NSArray *XUN; @property (nonatomic, strong) NSArray *XUN_KONG; @property (nonatomic, strong) NSArray *LIU_YAO; Lunar/Lunar/Tool/Lunar.m
@@ -121,6 +121,11 @@ + (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; @@ -128,13 +133,16 @@ 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; @@ -2832,18 +2840,36 @@ 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)) { @@ -2870,6 +2896,12 @@ + (NSInteger)getLeapMonth:(NSInteger)year { NSInteger index = year - [LunarUtil share].BASE_YEAR + [LunarUtil share].BASE_INDEX; 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; @@ -5040,7 +5072,7 @@ - (Lunar *)getLunar { return [Lunar fromDate:_calendar]; return [Lunar fromSolar:self]; } /** Lunar/Lunar/ViewController.m
@@ -20,8 +20,8 @@ self.view.backgroundColor = [UIColor redColor]; // Solar *d = [Solar fromYmdHms:2021 :4 :1 :0 :0 :0]; Solar *d = [Solar fromDate:[NSDate new]]; Solar *d = [Solar fromYmdHms:1901 :1 :1 :0 :0 :0]; // Solar *d = [Solar fromDate:[NSDate new]]; NSLog(@"公历:%@", [d toFullString]); Lunar *l = [d getLunar];