Struct icu_calendar::chinese::Chinese
source · pub struct Chinese {
data: Option<DataPayload<ChineseCacheV1Marker>>,
}
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.
Fields§
§data: Option<DataPayload<ChineseCacheV1Marker>>
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, CalendarError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Self, CalendarError>
A version of Self::new
that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_unstable<D: DataProvider<ChineseCacheV1Marker> + ?Sized>(
provider: &D,
) -> Result<Self, CalendarError>
pub fn try_new_unstable<D: DataProvider<ChineseCacheV1Marker> + ?Sized>( provider: &D, ) -> Result<Self, CalendarError>
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.
pub(crate) const DEBUG_NAME: &'static str = "Chinese"
source§impl Chinese
impl Chinese
sourcefn format_chinese_year(
year: i32,
year_info_option: Option<ChineseBasedYearInfo>,
) -> FormattableYear
fn format_chinese_year( year: i32, year_info_option: Option<ChineseBasedYearInfo>, ) -> FormattableYear
Get a FormattableYear from an integer Chinese year; optionally, a ChineseBasedYearInfo
can be passed in for faster results.
era
is always Era(tinystr!(16, "chinese"))
number
is the year since the inception of the Chinese calendar (see Chinese
)
cyclic
is an option with the current year in the sexagesimal cycle (see Chinese
)
related_iso
is the ISO year in which the given Chinese year begins (see Chinese
)
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: &Self::DateInner) -> FormattableYear
fn year(&self, date: &Self::DateInner) -> FormattableYear
The calendar-specific year represented by date
source§fn month(&self, date: &Self::DateInner) -> FormattableMonth
fn month(&self, date: &Self::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: &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§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<Self::DateInner, CalendarError>
fn date_from_codes( &self, era: Era, year: i32, month_code: MonthCode, day: u8, ) -> Result<Self::DateInner, CalendarError>
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 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 ChineseBasedWithDataLoading for Chinese
impl ChineseBasedWithDataLoading for Chinese
type CB = Chinese
source§fn get_precomputed_data(&self) -> ChineseBasedPrecomputedData<'_, Self::CB>
fn get_precomputed_data(&self) -> ChineseBasedPrecomputedData<'_, Self::CB>
None
if the given year
does not correspond to any compiled data.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: &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
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