pub struct LunisolarYear(/* private fields */);
Expand description
農曆西曆年,農曆新年所在的西曆年份。
Implementations§
source§impl LunisolarYear
impl LunisolarYear
用以建立 LunisolarYear
列舉實體的關聯函數。
sourcepub const unsafe fn from_solar_year_unsafe(solar_year: SolarYear) -> Self
pub const unsafe fn from_solar_year_unsafe(solar_year: SolarYear) -> Self
sourcepub const fn from_solar_year(
solar_year: SolarYear
) -> Result<Self, LunisolarOutOfRangeError>
pub const fn from_solar_year( solar_year: SolarYear ) -> Result<Self, LunisolarOutOfRangeError>
透過西曆年份來取得 LunisolarYear
實體。
Examples
use chinese_lunisolar_calendar::{LunisolarYear, SolarYear};
let lunisolar_year =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
source§impl LunisolarYear
impl LunisolarYear
將 LunisolarYear
列舉實體轉成其它型別的方法。
sourcepub const fn to_heavenly_stems(self) -> HeavenlyStems
pub const fn to_heavenly_stems(self) -> HeavenlyStems
取得此西曆年中,農曆新年的中國天干。
Examples
use chinese_lunisolar_calendar::{HeavenlyStems, LunisolarYear, SolarYear};
let lunisolar_year =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(HeavenlyStems::First, lunisolar_year.to_heavenly_stems());
sourcepub const fn to_earthly_branch(self) -> EarthlyBranch
pub const fn to_earthly_branch(self) -> EarthlyBranch
取得此西曆年中,農曆新年的中國地支。
Examples
use chinese_lunisolar_calendar::{EarthlyBranch, LunisolarYear, SolarYear};
let lunisolar_year =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(EarthlyBranch::Fifth, lunisolar_year.to_earthly_branch());
sourcepub const fn to_zodiac(self) -> Zodiac
pub const fn to_zodiac(self) -> Zodiac
取得此西曆年中,農曆新年所屬的生肖。
Examples
use chinese_lunisolar_calendar::{LunisolarYear, SolarYear, Zodiac};
let lunisolar_year =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(Zodiac::Dragon, lunisolar_year.to_zodiac());
sourcepub const fn to_lunar_year(self) -> LunarYear
pub const fn to_lunar_year(self) -> LunarYear
取得 LunarYear
實體。
Examples
use chinese_lunisolar_calendar::{LunarYear, LunisolarYear, SolarYear};
let lunisolar_year =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(
LunarYear::parse_str("甲辰").unwrap(),
lunisolar_year.to_lunar_year()
);
sourcepub const fn to_solar_year(self) -> SolarYear
pub const fn to_solar_year(self) -> SolarYear
取得 SolarYear
實體。
source§impl LunisolarYear
impl LunisolarYear
農曆西曆年相關計算方法。
sourcepub const fn get_leap_lunar_month(self) -> Option<LunarMonth>
pub const fn get_leap_lunar_month(self) -> Option<LunarMonth>
取得此年的農曆閏月月份。如果沒有的話就回傳 None
。
Examples
use chinese_lunisolar_calendar::{LunarMonth, LunisolarYear, SolarYear};
let lunisolar_year_2023 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2023)).unwrap();
let lunisolar_year_2024 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(
Some(LunarMonth::LeapSecond),
lunisolar_year_2023.get_leap_lunar_month()
);
assert_eq!(None, lunisolar_year_2024.get_leap_lunar_month());
sourcepub const fn get_total_days_in_leap_month(self) -> u16
pub const fn get_total_days_in_leap_month(self) -> u16
計算此西曆年下的農曆閏月共有幾天。如果沒有閏月,則回傳 0
。
Examples
use chinese_lunisolar_calendar::{LunisolarYear, SolarYear};
let lunisolar_year_2023 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2023)).unwrap();
let lunisolar_year_2024 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(29, lunisolar_year_2023.get_total_days_in_leap_month());
assert_eq!(0, lunisolar_year_2024.get_total_days_in_leap_month());
sourcepub const fn get_total_days(self) -> u16
pub const fn get_total_days(self) -> u16
計算此西曆年下的農曆年共有幾天。
Examples
use chinese_lunisolar_calendar::{LunisolarYear, SolarYear};
let lunisolar_year_2023 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2023)).unwrap();
let lunisolar_year_2024 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(384, lunisolar_year_2023.get_total_days());
assert_eq!(354, lunisolar_year_2024.get_total_days());
sourcepub const fn get_total_days_in_a_month(
self,
lunar_month: LunarMonth
) -> Option<u8>
pub const fn get_total_days_in_a_month( self, lunar_month: LunarMonth ) -> Option<u8>
計算此西曆年下的農曆年的某個月共有幾天。如果傳入的是閏月,但是該年沒有該閏月的話就回傳 None
。
Examples
use chinese_lunisolar_calendar::{LunarMonth, LunisolarYear, SolarYear};
let lunisolar_year_2023 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2023)).unwrap();
let lunisolar_year_2024 =
LunisolarYear::from_solar_year(SolarYear::from_u16(2024)).unwrap();
assert_eq!(
Some(29),
lunisolar_year_2023.get_total_days_in_a_month(LunarMonth::First)
);
assert_eq!(
Some(30),
lunisolar_year_2023.get_total_days_in_a_month(LunarMonth::Second)
);
assert_eq!(
Some(29),
lunisolar_year_2023.get_total_days_in_a_month(LunarMonth::LeapSecond)
);
assert_eq!(
Some(29),
lunisolar_year_2023.get_total_days_in_a_month(LunarMonth::Third)
);
assert_eq!(
None,
lunisolar_year_2023.get_total_days_in_a_month(LunarMonth::LeapThird)
);
assert_eq!(
Some(29),
lunisolar_year_2024.get_total_days_in_a_month(LunarMonth::First)
);
assert_eq!(
Some(30),
lunisolar_year_2024.get_total_days_in_a_month(LunarMonth::Second)
);
assert_eq!(
None,
lunisolar_year_2024.get_total_days_in_a_month(LunarMonth::LeapSecond)
);
assert_eq!(
Some(29),
lunisolar_year_2024.get_total_days_in_a_month(LunarMonth::Third)
);
assert_eq!(
None,
lunisolar_year_2024.get_total_days_in_a_month(LunarMonth::LeapThird)
);
Trait Implementations§
source§impl Clone for LunisolarYear
impl Clone for LunisolarYear
source§fn clone(&self) -> LunisolarYear
fn clone(&self) -> LunisolarYear
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for LunisolarYear
impl Debug for LunisolarYear
source§impl Display for LunisolarYear
impl Display for LunisolarYear
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter.
Examples
use chinese_lunisolar_calendar::{LunisolarYear, SolarYear};
let lunisolar_year =
LunisolarYear::from_solar_year(SolarYear::from_u16(2008)).unwrap();
assert_eq!("二〇〇八", format!("{}", lunisolar_year));
source§impl From<LunisolarDate> for LunisolarYear
impl From<LunisolarDate> for LunisolarYear
source§fn from(value: LunisolarDate) -> Self
fn from(value: LunisolarDate) -> Self
Converts to this type from the input type.
source§impl From<LunisolarYear> for EarthlyBranch
impl From<LunisolarYear> for EarthlyBranch
source§fn from(value: LunisolarYear) -> Self
fn from(value: LunisolarYear) -> Self
Converts to this type from the input type.
source§impl From<LunisolarYear> for HeavenlyStems
impl From<LunisolarYear> for HeavenlyStems
source§fn from(value: LunisolarYear) -> Self
fn from(value: LunisolarYear) -> Self
Converts to this type from the input type.
source§impl From<LunisolarYear> for LunarYear
impl From<LunisolarYear> for LunarYear
source§fn from(value: LunisolarYear) -> Self
fn from(value: LunisolarYear) -> Self
Converts to this type from the input type.
source§impl From<LunisolarYear> for SolarYear
impl From<LunisolarYear> for SolarYear
source§fn from(value: LunisolarYear) -> Self
fn from(value: LunisolarYear) -> Self
Converts to this type from the input type.
source§impl From<LunisolarYear> for Zodiac
impl From<LunisolarYear> for Zodiac
source§fn from(value: LunisolarYear) -> Self
fn from(value: LunisolarYear) -> Self
Converts to this type from the input type.
source§impl From<LunisolarYear> for u16
impl From<LunisolarYear> for u16
source§fn from(value: LunisolarYear) -> Self
fn from(value: LunisolarYear) -> Self
Converts to this type from the input type.
source§impl Hash for LunisolarYear
impl Hash for LunisolarYear
source§impl Ord for LunisolarYear
impl Ord for LunisolarYear
source§fn cmp(&self, other: &LunisolarYear) -> Ordering
fn cmp(&self, other: &LunisolarYear) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for LunisolarYear
impl PartialEq for LunisolarYear
source§fn eq(&self, other: &LunisolarYear) -> bool
fn eq(&self, other: &LunisolarYear) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for LunisolarYear
impl PartialOrd for LunisolarYear
source§fn partial_cmp(&self, other: &LunisolarYear) -> Option<Ordering>
fn partial_cmp(&self, other: &LunisolarYear) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl TryFrom<SolarYear> for LunisolarYear
impl TryFrom<SolarYear> for LunisolarYear
impl Copy for LunisolarYear
impl Eq for LunisolarYear
impl StructuralEq for LunisolarYear
impl StructuralPartialEq for LunisolarYear
Auto Trait Implementations§
impl RefUnwindSafe for LunisolarYear
impl Send for LunisolarYear
impl Sync for LunisolarYear
impl Unpin for LunisolarYear
impl UnwindSafe for LunisolarYear
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more