Skip to content

Commit

Permalink
v1.1.0 更改了get_year()、get_month()、get_day()的返回类型,非兼容性更新;新增吉神宜趋、凶神宜忌;新增…
Browse files Browse the repository at this point in the history
…每日宜忌、时辰宜忌;修复农历日获取时辰列表遇闰月报错的问题;修复获取当年第几周报错的问题。
  • Loading branch information
6tail committed Jul 14, 2024
1 parent 1a227bc commit 099bd8c
Show file tree
Hide file tree
Showing 9 changed files with 723 additions and 193 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@
3. 新增:入梅出梅。
4. 新增:获取农历日当天的时辰列表。
5. 新增:时辰获取黄道黑道十二神。

## [1.1.0] - 2024-07-14
1. 注意:此版本更改了get_year()、get_month()、get_day()的返回类型,非兼容性更新。
2. 新增:吉神宜趋、凶神宜忌。
3. 新增:每日宜忌、时辰宜忌。
4. 修复:农历日获取时辰列表遇闰月报错的问题。
5. 修复:获取当年第几周报错的问题。
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tyme4rs"
version = "1.0.4"
version = "1.1.0"
edition = "2021"
authors = ["6tail <[email protected]>"]
description = "Tyme是一个非常强大的日历工具库,可以看作 Lunar 的升级版,拥有更优的设计和扩展性,支持公历和农历、星座、干支、生肖、节气、法定假日等。"
Expand Down
20 changes: 10 additions & 10 deletions src/tyme/culture/eightchar/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
pub mod provider;

use std::fmt::{Display, Formatter};

use crate::tyme::{Culture, Tyme};
use crate::tyme::culture::Duty;
use crate::tyme::culture::eightchar::provider::{ChildLimitProvider};
use crate::tyme::culture::eightchar::provider::ChildLimitProvider;
use crate::tyme::enums::{Gender, YinYang};
use crate::tyme::lunar::LunarYear;
use crate::tyme::sixtycycle::{EarthBranch, HeavenStem, SixtyCycle};
use crate::tyme::solar::{SolarDay, SolarMonth, SolarTerm, SolarTime};
use crate::tyme::solar::{SolarDay, SolarTerm, SolarTime};

pub mod provider;

/// 八字
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -109,11 +110,11 @@ impl EightChar {
term = term.next(m).unwrap();
}
let solar_time: SolarTime = term.get_julian_day().get_solar_time();
if solar_time.get_day().get_month().get_year().get_year() >= start_year {
if solar_time.get_year() >= start_year {
let mut mi: usize = 0;
let mut s: usize = 0;
// 日干支和节令干支的偏移值
let mut solar_day: SolarDay = solar_time.get_day();
let mut solar_day: SolarDay = solar_time.get_solar_day();
let d: isize = self.day.next(-(solar_day.get_lunar_day().get_sixty_cycle().get_index() as isize)).unwrap().get_index() as isize;
if d > 0 {
// 从节令推移天数
Expand All @@ -123,8 +124,7 @@ impl EightChar {
mi = solar_time.get_minute();
s = solar_time.get_second();
}
let solar_month: SolarMonth = solar_day.get_month();
let time: SolarTime = SolarTime::from_ymd_hms(solar_month.get_year().get_year(), solar_month.get_month(), solar_day.get_day(), h, mi, s).unwrap();
let time: SolarTime = SolarTime::from_ymd_hms(solar_day.get_year(), solar_day.get_month(), solar_day.get_day(), h, mi, s).unwrap();
// 验证一下
if time.get_lunar_hour().get_eight_char() == *self {
l.push(time);
Expand Down Expand Up @@ -352,7 +352,7 @@ impl DecadeFortune {
}

pub fn get_start_lunar_year(&self) -> LunarYear {
self.child_limit.get_end_time().get_lunar_hour().get_day().get_month().get_year().next(self.index as isize * 10).unwrap()
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()
}

pub fn get_end_lunar(&self) -> LunarYear {
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Fortune {
}

pub fn get_lunar_year(&self) -> LunarYear {
self.child_limit.get_end_time().get_lunar_hour().get_day().get_month().get_year().next(self.index as isize).unwrap()
self.child_limit.get_end_time().get_lunar_hour().get_lunar_day().get_lunar_month().get_lunar_year().next(self.index as isize).unwrap()
}

pub fn get_sixty_cycle(&self) -> SixtyCycle {
Expand Down
23 changes: 9 additions & 14 deletions src/tyme/culture/eightchar/provider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::tyme::culture::eightchar::ChildLimitInfo;
use crate::tyme::solar::{SolarDay, SolarMonth, SolarTerm, SolarTime};
use crate::tyme::solar::{SolarMonth, SolarTerm, SolarTime};
use crate::tyme::Tyme;

pub trait ChildLimitProvider {
Expand Down Expand Up @@ -35,18 +35,15 @@ impl ChildLimitProvider for DefaultChildLimitProvider {
// 1秒 = 2分,1秒/2=0.5秒 = 1分
let minute: usize = seconds * 2;

let birthday: SolarDay = birth_time.get_day();
let birth_month: SolarMonth = birthday.get_month();

let mut d: usize = birthday.get_day() + day;
let mut d: usize = birth_time.get_day() + day;
let mut h: usize = birth_time.get_hour() + hour;
let mut mi: usize = birth_time.get_minute() + minute;
h += mi / 60;
mi %= 60;
d += h / 24;
h %= 24;

let mut sm: SolarMonth = SolarMonth::from_ym(birth_month.get_year().get_year() + year as isize, birth_month.get_month()).unwrap().next(month as isize).unwrap();
let mut sm: SolarMonth = SolarMonth::from_ym(birth_time.get_year() + year as isize, birth_time.get_month()).unwrap().next(month as isize).unwrap();

let dc: usize = sm.get_day_count();
if d > dc {
Expand All @@ -56,12 +53,12 @@ impl ChildLimitProvider for DefaultChildLimitProvider {

ChildLimitInfo {
start_time: birth_time,
end_time: SolarTime::from_ymd_hms(sm.get_year().get_year(), sm.get_month(), d, h, mi, birth_time.get_second()).unwrap(),
end_time: SolarTime::from_ymd_hms(sm.get_year(), sm.get_month(), d, h, mi, birth_time.get_second()).unwrap(),
year_count: year,
month_count: month,
day_count: day,
hour_count: hour,
minute_count: minute
minute_count: minute,
}
}
}
Expand All @@ -86,11 +83,9 @@ impl ChildLimitProvider for China95ChildLimitProvider {
minutes %= 360;
let day: usize = minutes / 12;

let birthday: SolarDay = birth_time.get_day();
let birth_month: SolarMonth = birthday.get_month();
let mut sm: SolarMonth = SolarMonth::from_ym(birth_month.get_year().get_year() + year as isize, birth_month.get_month()).unwrap().next(month as isize).unwrap();
let mut sm: SolarMonth = SolarMonth::from_ym(birth_time.get_year() + year as isize, birth_time.get_month()).unwrap().next(month as isize).unwrap();

let mut d: usize = birthday.get_day() + day;
let mut d: usize = birth_time.get_day() + day;
let dc: usize = sm.get_day_count();
if d > dc {
d -= dc;
Expand All @@ -99,12 +94,12 @@ impl ChildLimitProvider for China95ChildLimitProvider {

ChildLimitInfo {
start_time: birth_time,
end_time: SolarTime::from_ymd_hms(sm.get_year().get_year(), sm.get_month(), d,birth_time.get_hour(), birth_time.get_minute(), birth_time.get_second()).unwrap(),
end_time: SolarTime::from_ymd_hms(sm.get_year(), sm.get_month(), d, birth_time.get_hour(), birth_time.get_minute(), birth_time.get_second()).unwrap(),
year_count: year,
month_count: month,
day_count: day,
hour_count: 0,
minute_count: 0
minute_count: 0,
}
}
}
Loading

0 comments on commit 099bd8c

Please sign in to comment.