pub struct LunisolarYear(/* private fields */);
Expand description

農曆西曆年,農曆新年所在的西曆年份。

Implementations§

source§

impl LunisolarYear

用以建立 LunisolarYear 列舉實體的關聯函數。

source

pub const unsafe fn from_solar_year_unsafe(solar_year: SolarYear) -> Self

透過西曆年份來取得 LunisolarYear 實體。

Examples
use chinese_lunisolar_calendar::{LunisolarYear, SolarYear};

let lunisolar_year = unsafe {
    LunisolarYear::from_solar_year_unsafe(SolarYear::from_u16(2024))
};
Safety

必須先確認傳入的西曆年份是支援的。

source

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

LunisolarYear 列舉實體轉成其它型別的方法。

source

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());
source

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());
source

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());
source

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()
);
source

pub const fn to_solar_year(self) -> SolarYear

取得 SolarYear 實體。

source

pub const fn to_u16(self) -> u16

取得 LunisolarYear 實體所代表的西曆年份數值。

source§

impl LunisolarYear

農曆西曆年相關計算方法。

source

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());
source

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());
source

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());
source

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

source§

fn clone(&self) -> LunisolarYear

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LunisolarYear

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for LunisolarYear

source§

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

source§

fn from(value: LunisolarDate) -> Self

Converts to this type from the input type.
source§

impl From<LunisolarYear> for EarthlyBranch

source§

fn from(value: LunisolarYear) -> Self

Converts to this type from the input type.
source§

impl From<LunisolarYear> for HeavenlyStems

source§

fn from(value: LunisolarYear) -> Self

Converts to this type from the input type.
source§

impl From<LunisolarYear> for LunarYear

source§

fn from(value: LunisolarYear) -> Self

Converts to this type from the input type.
source§

impl From<LunisolarYear> for SolarYear

source§

fn from(value: LunisolarYear) -> Self

Converts to this type from the input type.
source§

impl From<LunisolarYear> for Zodiac

source§

fn from(value: LunisolarYear) -> Self

Converts to this type from the input type.
source§

impl From<LunisolarYear> for u16

source§

fn from(value: LunisolarYear) -> Self

Converts to this type from the input type.
source§

impl Hash for LunisolarYear

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for LunisolarYear

source§

fn cmp(&self, other: &LunisolarYear) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for LunisolarYear

source§

fn eq(&self, other: &LunisolarYear) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for LunisolarYear

source§

fn partial_cmp(&self, other: &LunisolarYear) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<SolarYear> for LunisolarYear

§

type Error = LunisolarOutOfRangeError

The type returned in the event of a conversion error.
source§

fn try_from(value: SolarYear) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for LunisolarYear

source§

impl Eq for LunisolarYear

source§

impl StructuralEq for LunisolarYear

source§

impl StructuralPartialEq for LunisolarYear

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.