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() -> Chinese
pub const fn new() -> Chinese
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<Chinese, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Chinese, 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<Chinese, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<Chinese, 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>(provider: &D) -> Result<Chinese, DataError>
pub fn try_new_unstable<D>(provider: &D) -> Result<Chinese, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
sourcepub fn new_always_calculating() -> Chinese
pub fn new_always_calculating() -> Chinese
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: &<Chinese as Calendar>::DateInner) -> MonthInfo
fn month(&self, date: &<Chinese as Calendar>::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: &<Chinese as Calendar>::DateInner) -> DayOfMonth
fn day_of_month(&self, date: &<Chinese as Calendar>::DateInner) -> DayOfMonth
The calendar-specific day-of-month represented by date
source§fn day_of_year_info(
&self,
date: &<Chinese as Calendar>::DateInner,
) -> DayOfYearInfo
fn day_of_year_info( &self, date: &<Chinese as Calendar>::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<<Chinese as Calendar>::DateInner, DateError>
fn date_from_codes( &self, era: Option<Era>, year: i32, month_code: MonthCode, day: u8, ) -> Result<<Chinese as Calendar>::DateInner, DateError>
source§fn date_from_iso(&self, iso: Date<Iso>) -> <Chinese as Calendar>::DateInner
fn date_from_iso(&self, iso: Date<Iso>) -> <Chinese as Calendar>::DateInner
source§fn date_to_iso(&self, date: &<Chinese as Calendar>::DateInner) -> Date<Iso>
fn date_to_iso(&self, date: &<Chinese as Calendar>::DateInner) -> Date<Iso>
source§fn days_in_year(&self, date: &<Chinese as Calendar>::DateInner) -> u16
fn days_in_year(&self, date: &<Chinese as Calendar>::DateInner) -> u16
source§fn days_in_month(&self, date: &<Chinese as Calendar>::DateInner) -> u8
fn days_in_month(&self, date: &<Chinese as Calendar>::DateInner) -> u8
source§fn year(&self, date: &<Chinese as Calendar>::DateInner) -> YearInfo
fn year(&self, date: &<Chinese as Calendar>::DateInner) -> YearInfo
source§fn is_in_leap_year(&self, date: &<Chinese as Calendar>::DateInner) -> bool
fn is_in_leap_year(&self, date: &<Chinese as Calendar>::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: &<Chinese as Calendar>::DateInner) -> u8
fn months_in_year(&self, date: &<Chinese as Calendar>::DateInner) -> u8
source§fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
fn day_of_week(&self, date: &Self::DateInner) -> IsoWeekday
source§impl CldrCalendar for Chinese
impl CldrCalendar for Chinese
source§type YearNamesV1Marker = ChineseYearNamesV1Marker
type YearNamesV1Marker = ChineseYearNamesV1Marker
source§type MonthNamesV1Marker = ChineseMonthNamesV1Marker
type MonthNamesV1Marker = ChineseMonthNamesV1Marker
source§type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker
type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker
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<Chinese, AnyCalendar>
fn from_any(any: AnyCalendar) -> Result<Chinese, AnyCalendar>
source§fn from_any_ref(any: &AnyCalendar) -> Option<&Chinese>
fn from_any_ref(any: &AnyCalendar) -> Option<&Chinese>
source§fn date_to_any(&self, d: &<Chinese as Calendar>::DateInner) -> AnyDateInner
fn date_to_any(&self, d: &<Chinese as Calendar>::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
impl UnstableSealed 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