pub struct Symmetry<const T: bool, const U: bool>(/* private fields */);
Expand description
Represents a date in one of the Symmetry calendars
§Introduction
The Symmetry calendars are a collection of calendar systems developed by Dr. Irvin L. Bromberg. Bromberg proposed 2 leap year rules and 2 month length rules, which can be combined to form 4 variants of the Symmetry calendar.
§Variants
T | U | Alias | Leap cycle | Quarter length |
---|---|---|---|---|
true | true | Symmetry454 | 293 year | 4 + 5 + 4 weeks |
false | true | Symmetry010 | 293 year | 30 + 31 + 30 days |
true | false | Symmetry454Solstice | 389 year | 4 + 5 + 4 weeks |
false | false | Symmetry010Solstice | 389 year | 30 + 31 + 30 days |
The combinations are summarized in the table above. Columns T
and U
are the type parameters.
Column Alias refers to the type aliases provided for convenience.
The placement of leap years is symmetric within a cycle - the length of the cycle is in column Leap Cycle. The 293 year leap rule approximates the northward equinox, while the 389 year rule approximates the north solstice.
Column Quarter Length refers to how days are distributed within a common year. Symmetry calendars have years split into 4 quarters. Each quarter is composed of 3 months. In Symmetry454 calendars, the months have lengths of 4, 5, and 4 weeks respectively. In Symmetry010 calendars, the months have lenghts of 30, 31, and 30 days respectively.
§Irvember
The Symmetry calendars have leap weeks instead of leap days. The extra week added in a leap year is a standalone thirteenth month called Irvember. Dr. Bromberg suggested an alternative scheme where the extra week is added to December instead of being standalone - however this alternative scheme is not implemented.
§Bromberg’s Warning
The calculations used in this library mirror Dr. Bromberg’s reference documents closely while still being idiomatic Rust. From Basic Symmetry454 and Symmetry010 Calendar Arithmetic by Bromberg:
Symmetry454 and Symmetry010 calendar arithmetic is very simple, but there is a tendency for those who are programming their first implementation of these calendars to immediately cut corners that may suffice for a limited range of dates, or to skip thorough validation of their implementation.
Please don’t deviate from the arithmetic outlined herein. Please “stick to the script”. Don’t try to invent your own arithmetic using novel expressions. There is no reason to do so, because this arithmetic is in the public domain, royalty free. The algorithm steps documented herein were carefully designed for efficiency, simplicity, and clarity of program code, and were thoroughly validated. Cutting corners will most likely result in harder-to-read programs that are more difficult to maintain and troubleshoot. In all probability a novel expression intended to “simplify” the arithmetic documented herein will actually prove to function erroneously under specific circumstances. It is just not worth wasting the time on the trouble that will make for you.
§Further reading
- Dr. Irvin L. Bromberg
Implementations§
Source§impl<const T: bool, const U: bool> Symmetry<T, U>
impl<const T: bool, const U: bool> Symmetry<T, U>
Sourcepub fn mode(self) -> (bool, bool)
pub fn mode(self) -> (bool, bool)
Returns (T, U)
T is true for Symmetry454 calendars and false for Symmetry010 calendars. U is true for the 292 year leap cycle and false for the 389 year leap cycle. See Symmetry for more details.
Sourcepub fn new_year_day_unchecked(sym_year: i32, sym_epoch: i64) -> i64
pub fn new_year_day_unchecked(sym_year: i32, sym_epoch: i64) -> i64
Returns the fixed day number of a Symmetry year
Sourcepub fn days_in_month(month: SymmetryMonth) -> u8
pub fn days_in_month(month: SymmetryMonth) -> u8
This function is not described by Dr. Bromberg and is not used in conversion to and from other timekeeping systems. Instead it is used for checking if a CommonDate is valid.
Trait Implementations§
Source§impl<const T: bool, const U: bool> CommonWeekOfYear<SymmetryMonth> for Symmetry<T, U>
impl<const T: bool, const U: bool> CommonWeekOfYear<SymmetryMonth> for Symmetry<T, U>
Source§impl<const T: bool, const U: bool> FromFixed for Symmetry<T, U>
impl<const T: bool, const U: bool> FromFixed for Symmetry<T, U>
fn from_fixed(fixed_date: Fixed) -> Symmetry<T, U>
Source§impl<const T: bool, const U: bool> GuaranteedMonth<SymmetryMonth> for Symmetry<T, U>
impl<const T: bool, const U: bool> GuaranteedMonth<SymmetryMonth> for Symmetry<T, U>
Source§impl<const T: bool, const U: bool> PartialOrd for Symmetry<T, U>
impl<const T: bool, const U: bool> PartialOrd for Symmetry<T, U>
Source§impl<const T: bool, const U: bool> PresetDisplay for Symmetry<T, U>
impl<const T: bool, const U: bool> PresetDisplay for Symmetry<T, U>
Source§fn supported_display_lang(lang: Language) -> bool
fn supported_display_lang(lang: Language) -> bool
Source§fn preset_str(&self, lang: Language, preset: PresetFormat<'_>) -> String
fn preset_str(&self, lang: Language, preset: PresetFormat<'_>) -> String
PresetFormat
Source§fn short_date(&self) -> String
fn short_date(&self) -> String
Source§impl<const T: bool, const U: bool> ToFromCommonDate<SymmetryMonth> for Symmetry<T, U>
impl<const T: bool, const U: bool> ToFromCommonDate<SymmetryMonth> for Symmetry<T, U>
Source§fn to_common_date(self) -> CommonDate
fn to_common_date(self) -> CommonDate
Source§fn from_common_date_unchecked(date: CommonDate) -> Self
fn from_common_date_unchecked(date: CommonDate) -> Self
Source§fn valid_ymd(date: CommonDate) -> Result<(), CalendarError>
fn valid_ymd(date: CommonDate) -> Result<(), CalendarError>
Source§fn year_end_date(year: i32) -> CommonDate
fn year_end_date(year: i32) -> CommonDate
Source§fn year_start_date(year: i32) -> CommonDate
fn year_start_date(year: i32) -> CommonDate
Source§fn in_effective_bounds(d: CommonDate) -> bool
fn in_effective_bounds(d: CommonDate) -> bool
Source§fn try_from_common_date(d: CommonDate) -> Result<Self, CalendarError>
fn try_from_common_date(d: CommonDate) -> Result<Self, CalendarError>
CommonDate
Source§fn try_year_start(year: i32) -> Result<Self, CalendarError>
fn try_year_start(year: i32) -> Result<Self, CalendarError>
Source§fn try_year_end(year: i32) -> Result<Self, CalendarError>
fn try_year_end(year: i32) -> Result<Self, CalendarError>
fn day(self) -> u8
fn year(self) -> i32
Source§impl<const T: bool, const U: bool> ToFromOrdinalDate for Symmetry<T, U>
impl<const T: bool, const U: bool> ToFromOrdinalDate for Symmetry<T, U>
Source§fn valid_ordinal(ord: OrdinalDate) -> Result<(), CalendarError>
fn valid_ordinal(ord: OrdinalDate) -> Result<(), CalendarError>
Source§fn ordinal_from_fixed(fixed_date: Fixed) -> OrdinalDate
fn ordinal_from_fixed(fixed_date: Fixed) -> OrdinalDate
Fixed
.Source§fn to_ordinal(self) -> OrdinalDate
fn to_ordinal(self) -> OrdinalDate
Source§fn from_ordinal_unchecked(ord: OrdinalDate) -> Self
fn from_ordinal_unchecked(ord: OrdinalDate) -> Self
Source§fn try_from_ordinal(ord: OrdinalDate) -> Result<Self, CalendarError>
fn try_from_ordinal(ord: OrdinalDate) -> Result<Self, CalendarError>
OrdinalDate