@@ -28,10 +28,10 @@ impl Culture for EightChar {
28
28
impl EightChar {
29
29
pub fn new ( year : & str , month : & str , day : & str , hour : & str ) -> Self {
30
30
Self {
31
- year : SixtyCycle :: from_name ( year) . unwrap ( ) ,
32
- month : SixtyCycle :: from_name ( month) . unwrap ( ) ,
33
- day : SixtyCycle :: from_name ( day) . unwrap ( ) ,
34
- hour : SixtyCycle :: from_name ( hour) . unwrap ( ) ,
31
+ year : SixtyCycle :: from_name ( year) ,
32
+ month : SixtyCycle :: from_name ( month) ,
33
+ day : SixtyCycle :: from_name ( day) ,
34
+ hour : SixtyCycle :: from_name ( hour) ,
35
35
}
36
36
}
37
37
@@ -61,25 +61,25 @@ impl EightChar {
61
61
}
62
62
63
63
pub fn get_fetal_origin ( & self ) -> SixtyCycle {
64
- SixtyCycle :: from_name ( format ! ( "{}{}" , self . month. get_heaven_stem( ) . next( 1 ) . unwrap ( ) . get_name( ) , self . month. get_earth_branch( ) . next( 3 ) . unwrap ( ) . get_name( ) ) . as_str ( ) ) . unwrap ( )
64
+ SixtyCycle :: from_name ( format ! ( "{}{}" , self . month. get_heaven_stem( ) . next( 1 ) . get_name( ) , self . month. get_earth_branch( ) . next( 3 ) . get_name( ) ) . as_str ( ) )
65
65
}
66
66
67
67
pub fn get_fetal_breath ( & self ) -> SixtyCycle {
68
- SixtyCycle :: from_name ( format ! ( "{}{}" , self . day. get_heaven_stem( ) . next( 5 ) . unwrap ( ) . get_name( ) , EarthBranch :: from_index( 13 - ( self . day. get_earth_branch( ) . get_index( ) as isize ) ) . get_name( ) ) . as_str ( ) ) . unwrap ( )
68
+ SixtyCycle :: from_name ( format ! ( "{}{}" , self . day. get_heaven_stem( ) . next( 5 ) . get_name( ) , EarthBranch :: from_index( 13 - ( self . day. get_earth_branch( ) . get_index( ) as isize ) ) . get_name( ) ) . as_str ( ) )
69
69
}
70
70
71
71
pub fn get_own_sign ( & self ) -> SixtyCycle {
72
- let mut offset: isize = ( self . month . get_earth_branch ( ) . next ( -1 ) . unwrap ( ) . get_index ( ) + self . hour . get_earth_branch ( ) . next ( -1 ) . unwrap ( ) . get_index ( ) ) as isize ;
72
+ let mut offset: isize = ( self . month . get_earth_branch ( ) . next ( -1 ) . get_index ( ) + self . hour . get_earth_branch ( ) . next ( -1 ) . get_index ( ) ) as isize ;
73
73
offset = if offset >= 14 { 26 } else { 14 } - offset;
74
74
offset -= 1 ;
75
- SixtyCycle :: from_name ( format ! ( "{}{}" , HeavenStem :: from_index( ( ( self . year. get_heaven_stem( ) . get_index( ) as isize ) + 1 ) * 2 + offset) . get_name( ) , EarthBranch :: from_index( 2 + offset) . get_name( ) ) . as_str ( ) ) . unwrap ( )
75
+ SixtyCycle :: from_name ( format ! ( "{}{}" , HeavenStem :: from_index( ( ( self . year. get_heaven_stem( ) . get_index( ) as isize ) + 1 ) * 2 + offset) . get_name( ) , EarthBranch :: from_index( 2 + offset) . get_name( ) ) . as_str ( ) )
76
76
}
77
77
78
78
pub fn get_body_sign ( & self ) -> SixtyCycle {
79
79
let mut offset: isize = ( self . month . get_earth_branch ( ) . get_index ( ) + self . hour . get_earth_branch ( ) . get_index ( ) ) as isize ;
80
80
offset %= 12 ;
81
81
offset -= 1 ;
82
- SixtyCycle :: from_name ( format ! ( "{}{}" , HeavenStem :: from_index( ( ( self . year. get_heaven_stem( ) . get_index( ) as isize ) + 1 ) * 2 + offset) . get_name( ) , EarthBranch :: from_index( 2 + offset) . get_name( ) ) . as_str ( ) ) . unwrap ( )
82
+ SixtyCycle :: from_name ( format ! ( "{}{}" , HeavenStem :: from_index( ( ( self . year. get_heaven_stem( ) . get_index( ) as isize ) + 1 ) * 2 + offset) . get_name( ) , EarthBranch :: from_index( 2 + offset) . get_name( ) ) . as_str ( ) )
83
83
}
84
84
85
85
pub fn get_duty ( & self ) -> Duty {
@@ -89,13 +89,13 @@ impl EightChar {
89
89
pub fn get_solar_times ( & self , start_year : isize , end_year : isize ) -> Vec < SolarTime > {
90
90
let mut l: Vec < SolarTime > = Vec :: new ( ) ;
91
91
// 月地支距寅月的偏移值
92
- let mut m: isize = self . month . get_earth_branch ( ) . next ( -2 ) . unwrap ( ) . get_index ( ) as isize ;
92
+ let mut m: isize = self . month . get_earth_branch ( ) . next ( -2 ) . get_index ( ) as isize ;
93
93
// 月天干要一致
94
94
if HeavenStem :: from_index ( ( self . year . get_heaven_stem ( ) . get_index ( ) as isize + 1 ) * 2 + m) != self . month . get_heaven_stem ( ) {
95
95
return l;
96
96
}
97
97
// 1年的立春是辛酉,序号57
98
- let mut y: isize = self . year . next ( -57 ) . unwrap ( ) . get_index ( ) as isize + 1 ;
98
+ let mut y: isize = self . year . next ( -57 ) . get_index ( ) as isize + 1 ;
99
99
// 节令偏移值
100
100
m *= 2 ;
101
101
// 时辰地支转时刻,子时按零点算
@@ -107,24 +107,24 @@ impl EightChar {
107
107
let mut term: SolarTerm = SolarTerm :: from_index ( y, 3 ) ;
108
108
// 节令推移,年干支和月干支就都匹配上了
109
109
if m > 0 {
110
- term = term. next ( m) . unwrap ( ) ;
110
+ term = term. next ( m) ;
111
111
}
112
112
let solar_time: SolarTime = term. get_julian_day ( ) . get_solar_time ( ) ;
113
113
if solar_time. get_year ( ) >= start_year {
114
114
let mut mi: usize = 0 ;
115
115
let mut s: usize = 0 ;
116
116
// 日干支和节令干支的偏移值
117
117
let mut solar_day: SolarDay = solar_time. get_solar_day ( ) ;
118
- let d: isize = self . day . next ( -( solar_day. get_lunar_day ( ) . get_sixty_cycle ( ) . get_index ( ) as isize ) ) . unwrap ( ) . get_index ( ) as isize ;
118
+ let d: isize = self . day . next ( -( solar_day. get_lunar_day ( ) . get_sixty_cycle ( ) . get_index ( ) as isize ) ) . get_index ( ) as isize ;
119
119
if d > 0 {
120
120
// 从节令推移天数
121
- solar_day = solar_day. next ( d) . unwrap ( ) ;
121
+ solar_day = solar_day. next ( d) ;
122
122
} else if h == solar_time. get_hour ( ) {
123
123
// 如果正好是节令当天,且小时和节令的小时数相等的极端情况,把分钟和秒钟带上
124
124
mi = solar_time. get_minute ( ) ;
125
125
s = solar_time. get_second ( ) ;
126
126
}
127
- let time: SolarTime = SolarTime :: from_ymd_hms ( solar_day. get_year ( ) , solar_day. get_month ( ) , solar_day. get_day ( ) , h, mi, s) . unwrap ( ) ;
127
+ let time: SolarTime = SolarTime :: from_ymd_hms ( solar_day. get_year ( ) , solar_day. get_month ( ) , solar_day. get_day ( ) , h, mi, s) ;
128
128
// 验证一下
129
129
if time. get_lunar_hour ( ) . get_eight_char ( ) == * self {
130
130
l. push ( time) ;
@@ -232,10 +232,10 @@ impl ChildLimit {
232
232
let forward: bool = ( yang && man) || ( !yang && !man) ;
233
233
let mut term: SolarTerm = birth_time. get_term ( ) ;
234
234
if !term. is_jie ( ) {
235
- term = term. next ( -1 ) . unwrap ( ) ;
235
+ term = term. next ( -1 ) ;
236
236
}
237
237
if forward {
238
- term = term. next ( 2 ) . unwrap ( ) ;
238
+ term = term. next ( 2 ) ;
239
239
}
240
240
let info: ChildLimitInfo = provider. get_info ( birth_time, term) ;
241
241
@@ -318,8 +318,8 @@ impl Culture for DecadeFortune {
318
318
}
319
319
320
320
impl Tyme for DecadeFortune {
321
- fn next ( & self , n : isize ) -> Result < Self , String > {
322
- Ok ( Self :: new ( self . get_child_limit ( ) , ( self . index as isize + n) as usize ) )
321
+ fn next ( & self , n : isize ) -> Self {
322
+ Self :: new ( self . get_child_limit ( ) , ( self . index as isize + n) as usize )
323
323
}
324
324
}
325
325
@@ -352,16 +352,16 @@ impl DecadeFortune {
352
352
}
353
353
354
354
pub fn get_start_lunar_year ( & self ) -> LunarYear {
355
- self . child_limit . get_end_time ( ) . get_lunar_hour ( ) . get_lunar_day ( ) . get_lunar_month ( ) . get_lunar_year ( ) . next ( self . index as isize * 10 ) . unwrap ( )
355
+ self . child_limit . get_end_time ( ) . get_lunar_hour ( ) . get_lunar_day ( ) . get_lunar_month ( ) . get_lunar_year ( ) . next ( self . index as isize * 10 )
356
356
}
357
357
358
358
pub fn get_end_lunar ( & self ) -> LunarYear {
359
- self . get_start_lunar_year ( ) . next ( 9 ) . unwrap ( )
359
+ self . get_start_lunar_year ( ) . next ( 9 )
360
360
}
361
361
362
362
pub fn get_sixty_cycle ( & self ) -> SixtyCycle {
363
363
let n: isize = self . index as isize + 1 ;
364
- self . child_limit . get_eight_char ( ) . get_month ( ) . next ( if self . child_limit . is_forward ( ) { n } else { -n } ) . unwrap ( )
364
+ self . child_limit . get_eight_char ( ) . get_month ( ) . next ( if self . child_limit . is_forward ( ) { n } else { -n } )
365
365
}
366
366
367
367
pub fn get_start_fortune ( & self ) -> Fortune {
@@ -391,8 +391,8 @@ impl Culture for Fortune {
391
391
}
392
392
393
393
impl Tyme for Fortune {
394
- fn next ( & self , n : isize ) -> Result < Self , String > {
395
- Ok ( Self :: new ( self . get_child_limit ( ) , ( self . get_index ( ) as isize + n) as usize ) )
394
+ fn next ( & self , n : isize ) -> Self {
395
+ Self :: new ( self . get_child_limit ( ) , ( self . get_index ( ) as isize + n) as usize )
396
396
}
397
397
}
398
398
@@ -421,12 +421,12 @@ impl Fortune {
421
421
}
422
422
423
423
pub fn get_lunar_year ( & self ) -> LunarYear {
424
- self . child_limit . get_end_time ( ) . get_lunar_hour ( ) . get_lunar_day ( ) . get_lunar_month ( ) . get_lunar_year ( ) . next ( self . index as isize ) . unwrap ( )
424
+ self . child_limit . get_end_time ( ) . get_lunar_hour ( ) . get_lunar_day ( ) . get_lunar_month ( ) . get_lunar_year ( ) . next ( self . index as isize )
425
425
}
426
426
427
427
pub fn get_sixty_cycle ( & self ) -> SixtyCycle {
428
428
let n: isize = self . get_age ( ) as isize ;
429
- self . child_limit . get_eight_char ( ) . get_hour ( ) . next ( if self . child_limit . is_forward ( ) { n } else { -n } ) . unwrap ( )
429
+ self . child_limit . get_eight_char ( ) . get_hour ( ) . next ( if self . child_limit . is_forward ( ) { n } else { -n } )
430
430
}
431
431
}
432
432
0 commit comments