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, CalendarError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized) ) -> Result<Chinese, CalendarError>
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, CalendarError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized) ) -> Result<Chinese, CalendarError>
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, CalendarError>
pub fn try_new_unstable<D>(provider: &D) -> Result<Chinese, CalendarError>
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 year(&self, date: &<Chinese as Calendar>::DateInner) -> FormattableYear
fn year(&self, date: &<Chinese as Calendar>::DateInner) -> FormattableYear
The calendar-specific year represented by date
source§fn month(&self, date: &<Chinese as Calendar>::DateInner) -> FormattableMonth
fn month(&self, date: &<Chinese as Calendar>::DateInner) -> FormattableMonth
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§fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
fn any_calendar_kind(&self) -> Option<AnyCalendarKind>
The AnyCalendarKind
corresponding to this calendar
§type DateInner = ChineseDateInner
type DateInner = ChineseDateInner
source§fn date_from_codes(
&self,
era: Era,
year: i32,
month_code: MonthCode,
day: u8
) -> Result<<Chinese as Calendar>::DateInner, CalendarError>
fn date_from_codes( &self, era: Era, year: i32, month_code: MonthCode, day: u8 ) -> Result<<Chinese as Calendar>::DateInner, CalendarError>
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 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 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§const DEFAULT_BCP_47_IDENTIFIER: Value = _
const DEFAULT_BCP_47_IDENTIFIER: Value = _
§type DateSymbolsV1Marker = ChineseDateSymbolsV1Marker
type DateSymbolsV1Marker = ChineseDateSymbolsV1Marker
§type DateLengthsV1Marker = ChineseDateLengthsV1Marker
type DateLengthsV1Marker = ChineseDateLengthsV1Marker
§type YearNamesV1Marker = ChineseYearNamesV1Marker
type YearNamesV1Marker = ChineseYearNamesV1Marker
§type MonthNamesV1Marker = ChineseMonthNamesV1Marker
type MonthNamesV1Marker = ChineseMonthNamesV1Marker
§type DatePatternV1Marker = ChineseDatePatternV1Marker
type DatePatternV1Marker = ChineseDatePatternV1Marker
§type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker
type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker
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 to_any_cloned(&self) -> AnyCalendar
fn to_any_cloned(&self) -> AnyCalendar
AnyCalendar
, cloning it Read moresource§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
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more