Struct icu_calendar::cal::Chinese
source · pub struct Chinese { /* private fields */ }
Expand description
The Chinese Calendar
The [Chinese Calendar] is a lunisolar calendar used traditionally in China as well as in other countries particularly in, but not limited to, East Asia. It is often used today to track important cultural events and holidays like the Chinese Lunar New Year.
This type can be used with Date
or DateTime
to represent dates in the Chinese calendar.
§Months
The Chinese calendar is an astronomical calendar which uses the phases of the moon to track months. Each month starts on the date of the new moon as observed from China, meaning that months last 29 or 30 days.
One year in the Chinese calendar is typically 12 lunar months; however, because 12 lunar months does not line up to one solar year, the Chinese calendar will add an intercalary leap month approximately every three years to keep Chinese calendar months in line with the solar year.
Leap months can happen after any month; the month in which a leap month occurs is based on the alignment of months with 24 solar terms into which the solar year is divided.
§Year and Era codes
Unlike the Gregorian calendar, the Chinese calendar does not traditionally count years in an infinitely increasing sequence. Instead, 10 “celestial stems” and 12 “terrestrial branches” are combined to form a cycle of year names which repeats every 60 years. However, for the purposes of calendar calculations and conversions, this module counts Chinese years in an infinite system similar to ISO, with year 1 in the calendar corresponding to the inception of the calendar, marked as 2637 BCE (ISO: -2636), and negative years marking Chinese years before February 15, 2637 BCE.
Because the Chinese calendar does not traditionally count years, era codes are not used in this calendar; this crate supports a single era code “chinese”.
This Chinese calendar implementation also supports a related ISO year, which marks the ISO year in which a Chinese year begins, and a cyclic year corresponding to the year in the 60 year cycle as described above.
For more information, suggested reading materials include:
- Calendrical Calculations by Reingold & Dershowitz
- The Mathematics of the Chinese Calendar by Helmer Aslaksen https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.139.9311&rep=rep1&type=pdf
- Wikipedia: https://en.wikipedia.org/wiki/Chinese_calendar
§Month codes
This calendar is a lunisolar calendar. It supports regular month codes "M01" - "M12"
as well
as leap month codes "M01L" - "M12L"
.
This calendar is currently in a preview state: formatting for this calendar is not going to be perfect.
Implementations§
source§impl Chinese
impl Chinese
sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new Chinese
with some precomputed calendrical calculations.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable<D: DataProvider<ChineseCacheV1Marker> + ?Sized>(
provider: &D,
) -> Result<Self, DataError>
pub fn try_new_unstable<D: DataProvider<ChineseCacheV1Marker> + ?Sized>( provider: &D, ) -> Result<Self, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
sourcepub fn new_always_calculating() -> Self
pub fn new_always_calculating() -> Self
Construct a new Chinese
without any precomputed calendrical calculations.
Trait Implementations§
source§impl Calendar for Chinese
impl Calendar for Chinese
source§fn debug_name(&self) -> &'static str
fn debug_name(&self) -> &'static str
Obtain a name for the calendar for debug printing
source§fn month(&self, date: &Self::DateInner) -> MonthInfo
fn month(&self, date: &Self::DateInner) -> MonthInfo
The calendar-specific month code represented by date
;
since the Chinese calendar has leap months, an “L” is appended to the month code for
leap months. For example, in a year where an intercalary month is added after the second
month, the month codes for ordinal months 1, 2, 3, 4, 5 would be “M01”, “M02”, “M02L”, “M03”, “M04”.
source§fn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth
fn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth
The calendar-specific day-of-month represented by date
source§fn day_of_year_info(&self, date: &Self::DateInner) -> DayOfYearInfo
fn day_of_year_info(&self, date: &Self::DateInner) -> DayOfYearInfo
Information of the day of the year
source§type DateInner = ChineseDateInner
type DateInner = ChineseDateInner
source§fn date_from_codes(
&self,
era: Option<Era>,
year: i32,
month_code: MonthCode,
day: u8,
) -> Result<Self::DateInner, DateError>
fn date_from_codes( &self, era: Option<Era>, year: i32, month_code: MonthCode, day: u8, ) -> Result<Self::DateInner, DateError>
source§fn date_from_iso(&self, iso: Date<Iso>) -> Self::DateInner
fn date_from_iso(&self, iso: Date<Iso>) -> Self::DateInner
source§fn days_in_year(&self, date: &Self::DateInner) -> u16
fn days_in_year(&self, date: &Self::DateInner) -> u16
source§fn days_in_month(&self, date: &Self::DateInner) -> u8
fn days_in_month(&self, date: &Self::DateInner) -> u8
source§fn is_in_leap_year(&self, date: &Self::DateInner) -> bool
fn is_in_leap_year(&self, date: &Self::DateInner) -> bool
source§fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
AnyCalendarKind
corresponding to this calendar,
if one exists. Implementors outside of icu::calendar
should return None
source§fn months_in_year(&self, date: &Self::DateInner) -> u8
fn months_in_year(&self, date: &Self::DateInner) -> u8
source§fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
source§impl From<Chinese> for AnyCalendar
impl From<Chinese> for AnyCalendar
source§fn from(value: Chinese) -> AnyCalendar
fn from(value: Chinese) -> AnyCalendar
source§impl IntoAnyCalendar for Chinese
impl IntoAnyCalendar for Chinese
source§fn to_any(self) -> AnyCalendar
fn to_any(self) -> AnyCalendar
AnyCalendar
, moving it Read moresource§fn kind(&self) -> AnyCalendarKind
fn kind(&self) -> AnyCalendarKind
AnyCalendarKind
enum variant associated with this calendarsource§fn to_any_cloned(&self) -> AnyCalendar
fn to_any_cloned(&self) -> AnyCalendar
AnyCalendar
, cloning it Read moresource§fn from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>
fn from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>
source§fn from_any_ref(any: &AnyCalendar) -> Option<&Self>
fn from_any_ref(any: &AnyCalendar) -> Option<&Self>
source§fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner
AnyDateInner
Read moresource§impl Ord for Chinese
impl Ord for Chinese
source§impl PartialOrd for Chinese
impl PartialOrd for Chinese
impl Eq for Chinese
Auto Trait Implementations§
impl Freeze for Chinese
impl RefUnwindSafe for Chinese
impl Send for Chinese
impl Sync for Chinese
impl Unpin for Chinese
impl UnwindSafe for Chinese
Blanket Implementations§
source§impl<C> AsCalendar for Cwhere
C: Calendar,
impl<C> AsCalendar for Cwhere
C: Calendar,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more