Skip to content

Commit 98f693d

Browse files
committed
v1.3.0 新增干支年、干支月、干支日、干支时辰;新增童限的所属大运、开始年龄、结束年龄;废弃八字的建除十二值神;废弃农历日的当天年干支、当天月干支;废弃农历时辰的当时年干支、当时月干支、当时日干支;废弃童限的结束农历年;废弃大运的开始农历年、结束农历年;废弃小运的农历年;修复八字身宫计算错误的问题;优化包结构。
1 parent 189329d commit 98f693d

File tree

11 files changed

+724
-143
lines changed

11 files changed

+724
-143
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,15 @@
6464
1. 优化:简化代码。
6565
2. 优化:流年计算逻辑。
6666
3. 优化:优化节气推移。
67+
68+
## [1.3.0] - 2025-04-18
69+
1. 新增:干支年、干支月、干支日、干支时辰。
70+
2. 新增:童限的所属大运、开始年龄、结束年龄。
71+
3. 废弃:八字的建除十二值神(建议从干支日中获取)。
72+
4. 废弃:农历日的当天年干支、当天月干支(建议从干支日中获取)。
73+
5. 废弃:农历时辰的当时年干支、当时月干支、当时日干支(建议从干支时辰中获取)。
74+
6. 废弃:童限的结束农历年(建议取结束干支年)。
75+
7. 废弃:大运的开始农历年、结束农历年(建议取开始干支年、结束干支年)。
76+
8. 废弃:小运的农历年(建议取干支年)。
77+
9. 修复:八字身宫计算错误的问题。
78+
10. 优化:包结构。

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tyme4rs"
3-
version = "1.1.8"
3+
version = "1.3.0"
44
edition = "2021"
55
authors = ["6tail <[email protected]>"]
66
description = "Tyme是一个非常强大的日历工具库,可以看作 Lunar 的升级版,拥有更优的设计和扩展性,支持公历和农历、星座、干支、生肖、节气、法定假日等。"

src/tyme/culture/fetus.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::tyme::culture::Direction;
44
use crate::tyme::enums::Side;
55
use crate::tyme::{Culture, LoopTyme, Tyme};
66
use crate::tyme::lunar::{LunarDay, LunarMonth};
7-
use crate::tyme::sixtycycle::SixtyCycle;
7+
use crate::tyme::sixtycycle::{SixtyCycle, SixtyCycleDay};
88

99
/// 逐日胎神
1010
#[derive(Debug, Clone)]
@@ -16,8 +16,7 @@ pub struct FetusDay {
1616
}
1717

1818
impl FetusDay {
19-
pub fn from_lunar_day(lunar_day: LunarDay) -> Self {
20-
let sixty_cycle: SixtyCycle = lunar_day.get_sixty_cycle();
19+
pub fn new(sixty_cycle: SixtyCycle) -> Self {
2120
let fetus_heaven_stem: FetusHeavenStem = FetusHeavenStem::from_index((sixty_cycle.get_heaven_stem().get_index() as isize) % 5);
2221
let fetus_earth_branch: FetusEarthBranch = FetusEarthBranch::from_index((sixty_cycle.get_earth_branch().get_index() as isize) % 6);
2322
let index: isize = [3, 3, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, -9, -9, -9, -9, -9, -5, -5, -1, -1, -1, -3, -7, -7, -7, -7, -5, 7, 7, 7, 7, 7, 7, 2, 2, 2, 2, 2, 3, 3, 3, 3][sixty_cycle.get_index()];
@@ -32,6 +31,14 @@ impl FetusDay {
3231
}
3332
}
3433

34+
pub fn from_lunar_day(lunar_day: LunarDay) -> Self {
35+
Self::new(lunar_day.get_sixty_cycle())
36+
}
37+
38+
pub fn from_sixty_cycle_day(sixty_cycle_day: SixtyCycleDay) -> Self {
39+
Self::new(sixty_cycle_day.get_sixty_cycle())
40+
}
41+
3542
pub fn get_fetus_heaven_stem(&self) -> FetusHeavenStem {
3643
self.fetus_heaven_stem.clone()
3744
}

src/tyme/culture/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,6 @@ pub mod fetus;
14291429
pub mod peng_zu;
14301430
pub mod phenology;
14311431
pub mod star;
1432-
pub mod eightchar;
14331432
pub mod plumrain;
14341433
pub mod ren;
14351434

src/tyme/culture/eightchar/mod.rs renamed to src/tyme/eightchar/mod.rs

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use lazy_static::lazy_static;
55

66
use crate::tyme::{Culture, Tyme};
77
use crate::tyme::culture::Duty;
8-
use crate::tyme::culture::eightchar::provider::{ChildLimitProvider, DefaultChildLimitProvider};
8+
use crate::tyme::eightchar::provider::{ChildLimitProvider, DefaultChildLimitProvider};
99
use crate::tyme::enums::{Gender, YinYang};
1010
use crate::tyme::lunar::LunarYear;
11-
use crate::tyme::sixtycycle::{EarthBranch, HeavenStem, SixtyCycle};
11+
use crate::tyme::sixtycycle::{EarthBranch, HeavenStem, SixtyCycle, SixtyCycleYear};
1212
use crate::tyme::solar::{SolarDay, SolarTerm, SolarTime};
1313

1414
pub mod provider;
@@ -79,12 +79,11 @@ impl EightChar {
7979
}
8080

8181
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;
8583
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())
8684
}
8785

86+
#[deprecated(since = "1.3.0", note = "please use SixtyCycleDay.get_duty() instead")]
8887
pub fn get_duty(&self) -> Duty {
8988
Duty::from_index((self.day.get_earth_branch().get_index() as isize) - (self.month.get_earth_branch().get_index() as isize))
9089
}
@@ -302,17 +301,48 @@ impl ChildLimit {
302301
self.info.get_end_time()
303302
}
304303

304+
/// 起始大运
305305
pub fn get_start_decade_fortune(&self) -> DecadeFortune {
306306
DecadeFortune::from_child_limit(self.clone(), 0)
307307
}
308308

309+
/// 所属大运
310+
pub fn get_decade_fortune(&self) -> DecadeFortune {
311+
DecadeFortune::from_child_limit(self.clone(), -1)
312+
}
313+
309314
pub fn get_start_fortune(&self) -> Fortune {
310315
Fortune::from_child_limit(self.clone(), 0)
311316
}
312317

318+
#[deprecated(since = "1.3.0", note = "please use get_end_sixty_cycle_year() instead")]
313319
pub fn get_end_lunar_year(&self) -> LunarYear {
314320
LunarYear::from_year(self.get_start_time().get_lunar_hour().get_year() + self.get_end_time().get_year() - self.get_start_time().get_year())
315321
}
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+
}
316346
}
317347

318348
impl PartialEq for ChildLimit {
@@ -327,7 +357,7 @@ impl Eq for ChildLimit {}
327357
#[derive(Debug, Clone)]
328358
pub struct DecadeFortune {
329359
child_limit: ChildLimit,
330-
index: usize,
360+
index: isize,
331361
}
332362

333363
impl Culture for DecadeFortune {
@@ -338,48 +368,60 @@ impl Culture for DecadeFortune {
338368

339369
impl Tyme for DecadeFortune {
340370
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)
342372
}
343373
}
344374

345375
impl DecadeFortune {
346-
pub fn new(child_limit: ChildLimit, index: usize) -> Self {
376+
pub fn new(child_limit: ChildLimit, index: isize) -> Self {
347377
Self {
348378
child_limit,
349379
index,
350380
}
351381
}
352382

353-
pub fn from_child_limit(child_limit: ChildLimit, index: usize) -> Self {
383+
pub fn from_child_limit(child_limit: ChildLimit, index: isize) -> Self {
354384
Self::new(child_limit, index)
355385
}
356386

357387
pub fn get_child_limit(&self) -> ChildLimit {
358388
self.child_limit.clone()
359389
}
360390

361-
pub fn get_index(&self) -> usize {
391+
pub fn get_index(&self) -> isize {
362392
self.index
363393
}
364394

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
367397
}
368398

369-
pub fn get_end_age(&self) -> usize {
399+
pub fn get_end_age(&self) -> isize {
370400
self.get_start_age() + 9
371401
}
372402

403+
#[deprecated(since = "1.3.0", note = "please use get_start_sixty_cycle_year() instead")]
373404
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)
375406
}
376407

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)
379421
}
380422

381423
pub fn get_sixty_cycle(&self) -> SixtyCycle {
382-
let n: isize = self.index as isize + 1;
424+
let n: isize = self.index + 1;
383425
self.child_limit.get_eight_char().get_month().next(if self.child_limit.is_forward() { n } else { -n })
384426
}
385427

@@ -400,7 +442,7 @@ impl Eq for DecadeFortune {}
400442
#[derive(Debug, Clone)]
401443
pub struct Fortune {
402444
child_limit: ChildLimit,
403-
index: usize,
445+
index: isize,
404446
}
405447

406448
impl Culture for Fortune {
@@ -411,40 +453,46 @@ impl Culture for Fortune {
411453

412454
impl Tyme for Fortune {
413455
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)
415457
}
416458
}
417459

418460
impl Fortune {
419-
pub fn new(child_limit: ChildLimit, index: usize) -> Self {
461+
pub fn new(child_limit: ChildLimit, index: isize) -> Self {
420462
Self {
421463
child_limit,
422464
index,
423465
}
424466
}
425467

426-
pub fn from_child_limit(child_limit: ChildLimit, index: usize) -> Self {
468+
pub fn from_child_limit(child_limit: ChildLimit, index: isize) -> Self {
427469
Self::new(child_limit, index)
428470
}
429471

430472
pub fn get_child_limit(&self) -> ChildLimit {
431473
self.child_limit.clone()
432474
}
433475

434-
pub fn get_index(&self) -> usize {
476+
pub fn get_index(&self) -> isize {
435477
self.index
436478
}
437479

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
440482
}
441483

484+
#[deprecated(since = "1.3.0", note = "please use get_sixty_cycle_year() instead")]
442485
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)
444492
}
445493

446494
pub fn get_sixty_cycle(&self) -> SixtyCycle {
447-
let n: isize = self.get_age() as isize;
495+
let n: isize = self.get_age();
448496
self.child_limit.get_eight_char().get_hour().next(if self.child_limit.is_forward() { n } else { -n })
449497
}
450498
}
@@ -460,8 +508,8 @@ impl Eq for Fortune {}
460508
#[cfg(test)]
461509
mod tests {
462510
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};
465513
use crate::tyme::enums::Gender;
466514
use crate::tyme::solar::SolarTime;
467515

src/tyme/culture/eightchar/provider.rs renamed to src/tyme/eightchar/provider.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::tyme::culture::eightchar::{ChildLimitInfo, EightChar};
1+
use crate::tyme::eightchar::{ChildLimitInfo, EightChar};
22
use crate::tyme::lunar::LunarHour;
3+
use crate::tyme::sixtycycle::SixtyCycleHour;
34
use crate::tyme::solar::{SolarMonth, SolarTerm, SolarTime};
45
use crate::tyme::Tyme;
56

@@ -26,7 +27,7 @@ impl DefaultEightCharProvider {
2627

2728
impl EightCharProvider for DefaultEightCharProvider {
2829
fn get_eight_char(&self, hour: LunarHour) -> EightChar {
29-
EightChar::from_sixty_cycle(hour.get_year_sixty_cycle(), hour.get_month_sixty_cycle(), hour.get_day_sixty_cycle(), hour.get_sixty_cycle())
30+
hour.get_sixty_cycle_hour().get_eight_char()
3031
}
3132
}
3233

@@ -43,7 +44,8 @@ impl LunarSect2EightCharProvider {
4344

4445
impl EightCharProvider for LunarSect2EightCharProvider {
4546
fn get_eight_char(&self, hour: LunarHour) -> EightChar {
46-
EightChar::from_sixty_cycle(hour.get_year_sixty_cycle(), hour.get_month_sixty_cycle(), hour.get_lunar_day().get_sixty_cycle(), hour.get_sixty_cycle())
47+
let h: SixtyCycleHour = hour.get_sixty_cycle_hour();
48+
EightChar::from_sixty_cycle(h.get_year(), h.get_month(), hour.get_lunar_day().get_sixty_cycle(), h.get_sixty_cycle())
4749
}
4850
}
4951

src/tyme/festival.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl LunarFestival {
264264
}
265265

266266
pub fn get_day(&self) -> LunarDay {
267-
self.day
267+
self.day.clone()
268268
}
269269

270270
pub fn get_solar_term(&self) -> Option<SolarTerm> {

0 commit comments

Comments
 (0)