@@ -5,10 +5,10 @@ use lazy_static::lazy_static;
5
5
6
6
use crate :: tyme:: { Culture , Tyme } ;
7
7
use crate :: tyme:: culture:: Duty ;
8
- use crate :: tyme:: culture :: eightchar:: provider:: { ChildLimitProvider , DefaultChildLimitProvider } ;
8
+ use crate :: tyme:: eightchar:: provider:: { ChildLimitProvider , DefaultChildLimitProvider } ;
9
9
use crate :: tyme:: enums:: { Gender , YinYang } ;
10
10
use crate :: tyme:: lunar:: LunarYear ;
11
- use crate :: tyme:: sixtycycle:: { EarthBranch , HeavenStem , SixtyCycle } ;
11
+ use crate :: tyme:: sixtycycle:: { EarthBranch , HeavenStem , SixtyCycle , SixtyCycleYear } ;
12
12
use crate :: tyme:: solar:: { SolarDay , SolarTerm , SolarTime } ;
13
13
14
14
pub mod provider;
@@ -79,12 +79,11 @@ impl EightChar {
79
79
}
80
80
81
81
pub fn get_body_sign ( & self ) -> SixtyCycle {
82
- let mut offset: isize = ( self . month . get_earth_branch ( ) . get_index ( ) + self . hour . get_earth_branch ( ) . get_index ( ) ) as isize ;
83
- offset %= 12 ;
84
- offset -= 1 ;
82
+ let offset: isize = ( self . month . get_earth_branch ( ) . get_index ( ) as isize + self . hour . get_earth_branch ( ) . get_index ( ) as isize - 1 ) % 12 ;
85
83
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 ( ) )
86
84
}
87
85
86
+ #[ deprecated( since = "1.3.0" , note = "please use SixtyCycleDay.get_duty() instead" ) ]
88
87
pub fn get_duty ( & self ) -> Duty {
89
88
Duty :: from_index ( ( self . day . get_earth_branch ( ) . get_index ( ) as isize ) - ( self . month . get_earth_branch ( ) . get_index ( ) as isize ) )
90
89
}
@@ -302,17 +301,48 @@ impl ChildLimit {
302
301
self . info . get_end_time ( )
303
302
}
304
303
304
+ /// 起始大运
305
305
pub fn get_start_decade_fortune ( & self ) -> DecadeFortune {
306
306
DecadeFortune :: from_child_limit ( self . clone ( ) , 0 )
307
307
}
308
308
309
+ /// 所属大运
310
+ pub fn get_decade_fortune ( & self ) -> DecadeFortune {
311
+ DecadeFortune :: from_child_limit ( self . clone ( ) , -1 )
312
+ }
313
+
309
314
pub fn get_start_fortune ( & self ) -> Fortune {
310
315
Fortune :: from_child_limit ( self . clone ( ) , 0 )
311
316
}
312
317
318
+ #[ deprecated( since = "1.3.0" , note = "please use get_end_sixty_cycle_year() instead" ) ]
313
319
pub fn get_end_lunar_year ( & self ) -> LunarYear {
314
320
LunarYear :: from_year ( self . get_start_time ( ) . get_lunar_hour ( ) . get_year ( ) + self . get_end_time ( ) . get_year ( ) - self . get_start_time ( ) . get_year ( ) )
315
321
}
322
+
323
+ /// 开始(即出生)干支年
324
+ pub fn get_start_sixty_cycle_year ( & self ) -> SixtyCycleYear {
325
+ SixtyCycleYear :: from_year ( self . get_start_time ( ) . get_year ( ) )
326
+ }
327
+
328
+ /// 结束(即起运)干支年
329
+ pub fn get_end_sixty_cycle_year ( & self ) -> SixtyCycleYear {
330
+ SixtyCycleYear :: from_year ( self . get_end_time ( ) . get_year ( ) )
331
+ }
332
+
333
+ /// 开始年龄
334
+ pub fn get_start_age ( & self ) -> usize {
335
+ 1
336
+ }
337
+
338
+ /// 结束年龄
339
+ pub fn get_end_age ( & self ) -> usize {
340
+ let n: isize = self . get_end_sixty_cycle_year ( ) . get_year ( ) - self . get_start_sixty_cycle_year ( ) . get_year ( ) ;
341
+ if n > 1 {
342
+ return n as usize ;
343
+ }
344
+ 1
345
+ }
316
346
}
317
347
318
348
impl PartialEq for ChildLimit {
@@ -327,7 +357,7 @@ impl Eq for ChildLimit {}
327
357
#[ derive( Debug , Clone ) ]
328
358
pub struct DecadeFortune {
329
359
child_limit : ChildLimit ,
330
- index : usize ,
360
+ index : isize ,
331
361
}
332
362
333
363
impl Culture for DecadeFortune {
@@ -338,48 +368,60 @@ impl Culture for DecadeFortune {
338
368
339
369
impl Tyme for DecadeFortune {
340
370
fn next ( & self , n : isize ) -> Self {
341
- Self :: new ( self . get_child_limit ( ) , ( self . index as isize + n) as usize )
371
+ Self :: new ( self . get_child_limit ( ) , self . index + n)
342
372
}
343
373
}
344
374
345
375
impl DecadeFortune {
346
- pub fn new ( child_limit : ChildLimit , index : usize ) -> Self {
376
+ pub fn new ( child_limit : ChildLimit , index : isize ) -> Self {
347
377
Self {
348
378
child_limit,
349
379
index,
350
380
}
351
381
}
352
382
353
- pub fn from_child_limit ( child_limit : ChildLimit , index : usize ) -> Self {
383
+ pub fn from_child_limit ( child_limit : ChildLimit , index : isize ) -> Self {
354
384
Self :: new ( child_limit, index)
355
385
}
356
386
357
387
pub fn get_child_limit ( & self ) -> ChildLimit {
358
388
self . child_limit . clone ( )
359
389
}
360
390
361
- pub fn get_index ( & self ) -> usize {
391
+ pub fn get_index ( & self ) -> isize {
362
392
self . index
363
393
}
364
394
365
- pub fn get_start_age ( & self ) -> usize {
366
- ( self . child_limit . get_end_time ( ) . get_year ( ) - self . child_limit . get_start_time ( ) . get_year ( ) ) as usize + 1 + self . index * 10
395
+ pub fn get_start_age ( & self ) -> isize {
396
+ self . child_limit . get_end_sixty_cycle_year ( ) . get_year ( ) - self . child_limit . get_start_sixty_cycle_year ( ) . get_year ( ) + 1 + self . index * 10
367
397
}
368
398
369
- pub fn get_end_age ( & self ) -> usize {
399
+ pub fn get_end_age ( & self ) -> isize {
370
400
self . get_start_age ( ) + 9
371
401
}
372
402
403
+ #[ deprecated( since = "1.3.0" , note = "please use get_start_sixty_cycle_year() instead" ) ]
373
404
pub fn get_start_lunar_year ( & self ) -> LunarYear {
374
- self . child_limit . get_end_lunar_year ( ) . next ( self . index as isize * 10 )
405
+ LunarYear :: from_year ( self . child_limit . get_start_time ( ) . get_lunar_hour ( ) . get_year ( ) + self . child_limit . get_end_time ( ) . get_year ( ) - self . child_limit . get_start_time ( ) . get_year ( ) ) . next ( self . index * 10 )
375
406
}
376
407
377
- pub fn get_end_lunar ( & self ) -> LunarYear {
378
- self . get_start_lunar_year ( ) . next ( 9 )
408
+ /// 开始干支年
409
+ pub fn get_start_sixty_cycle_year ( & self ) -> SixtyCycleYear {
410
+ self . child_limit . get_end_sixty_cycle_year ( ) . next ( self . index * 10 )
411
+ }
412
+
413
+ #[ deprecated( since = "1.3.0" , note = "please use get_end_sixty_cycle_year() instead" ) ]
414
+ pub fn get_end_lunar_year ( & self ) -> LunarYear {
415
+ LunarYear :: from_year ( self . child_limit . get_start_time ( ) . get_lunar_hour ( ) . get_year ( ) + self . child_limit . get_end_time ( ) . get_year ( ) - self . child_limit . get_start_time ( ) . get_year ( ) ) . next ( self . index * 10 + 9 )
416
+ }
417
+
418
+ /// 结束干支年
419
+ pub fn get_end_sixty_cycle_year ( & self ) -> SixtyCycleYear {
420
+ self . get_start_sixty_cycle_year ( ) . next ( 9 )
379
421
}
380
422
381
423
pub fn get_sixty_cycle ( & self ) -> SixtyCycle {
382
- let n: isize = self . index as isize + 1 ;
424
+ let n: isize = self . index + 1 ;
383
425
self . child_limit . get_eight_char ( ) . get_month ( ) . next ( if self . child_limit . is_forward ( ) { n } else { -n } )
384
426
}
385
427
@@ -400,7 +442,7 @@ impl Eq for DecadeFortune {}
400
442
#[ derive( Debug , Clone ) ]
401
443
pub struct Fortune {
402
444
child_limit : ChildLimit ,
403
- index : usize ,
445
+ index : isize ,
404
446
}
405
447
406
448
impl Culture for Fortune {
@@ -411,40 +453,46 @@ impl Culture for Fortune {
411
453
412
454
impl Tyme for Fortune {
413
455
fn next ( & self , n : isize ) -> Self {
414
- Self :: new ( self . get_child_limit ( ) , ( self . get_index ( ) as isize + n) as usize )
456
+ Self :: new ( self . get_child_limit ( ) , self . get_index ( ) + n)
415
457
}
416
458
}
417
459
418
460
impl Fortune {
419
- pub fn new ( child_limit : ChildLimit , index : usize ) -> Self {
461
+ pub fn new ( child_limit : ChildLimit , index : isize ) -> Self {
420
462
Self {
421
463
child_limit,
422
464
index,
423
465
}
424
466
}
425
467
426
- pub fn from_child_limit ( child_limit : ChildLimit , index : usize ) -> Self {
468
+ pub fn from_child_limit ( child_limit : ChildLimit , index : isize ) -> Self {
427
469
Self :: new ( child_limit, index)
428
470
}
429
471
430
472
pub fn get_child_limit ( & self ) -> ChildLimit {
431
473
self . child_limit . clone ( )
432
474
}
433
475
434
- pub fn get_index ( & self ) -> usize {
476
+ pub fn get_index ( & self ) -> isize {
435
477
self . index
436
478
}
437
479
438
- pub fn get_age ( & self ) -> usize {
439
- ( self . child_limit . get_end_time ( ) . get_year ( ) - self . child_limit . get_start_time ( ) . get_year ( ) ) as usize + 1 + self . index
480
+ pub fn get_age ( & self ) -> isize {
481
+ self . child_limit . get_end_sixty_cycle_year ( ) . get_year ( ) - self . child_limit . get_start_sixty_cycle_year ( ) . get_year ( ) + 1 + self . index
440
482
}
441
483
484
+ #[ deprecated( since = "1.3.0" , note = "please use get_sixty_cycle_year() instead" ) ]
442
485
pub fn get_lunar_year ( & self ) -> LunarYear {
443
- self . child_limit . get_end_lunar_year ( ) . next ( self . index as isize )
486
+ LunarYear :: from_year ( self . child_limit . get_start_time ( ) . get_lunar_hour ( ) . get_year ( ) + self . child_limit . get_end_time ( ) . get_year ( ) - self . child_limit . get_start_time ( ) . get_year ( ) ) . next ( self . index )
487
+ }
488
+
489
+ /// 干支年
490
+ pub fn get_sixty_cycle_year ( & self ) -> SixtyCycleYear {
491
+ self . child_limit . get_end_sixty_cycle_year ( ) . next ( self . index )
444
492
}
445
493
446
494
pub fn get_sixty_cycle ( & self ) -> SixtyCycle {
447
- let n: isize = self . get_age ( ) as isize ;
495
+ let n: isize = self . get_age ( ) ;
448
496
self . child_limit . get_eight_char ( ) . get_hour ( ) . next ( if self . child_limit . is_forward ( ) { n } else { -n } )
449
497
}
450
498
}
@@ -460,8 +508,8 @@ impl Eq for Fortune {}
460
508
#[ cfg( test) ]
461
509
mod tests {
462
510
use std:: sync:: MutexGuard ;
463
- use crate :: tyme:: culture :: eightchar:: { CHILD_LIMIT_PROVIDER , ChildLimit } ;
464
- use crate :: tyme:: culture :: eightchar:: provider:: { ChildLimitProvider , DefaultChildLimitProvider } ;
511
+ use crate :: tyme:: eightchar:: { CHILD_LIMIT_PROVIDER , ChildLimit } ;
512
+ use crate :: tyme:: eightchar:: provider:: { ChildLimitProvider , DefaultChildLimitProvider } ;
465
513
use crate :: tyme:: enums:: Gender ;
466
514
use crate :: tyme:: solar:: SolarTime ;
467
515
0 commit comments