Struct Symmetry

Source
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

TUAliasLeap cycleQuarter length
truetrueSymmetry454293 year4 + 5 + 4 weeks
falsetrueSymmetry010293 year30 + 31 + 30 days
truefalseSymmetry454Solstice389 year4 + 5 + 4 weeks
falsefalseSymmetry010Solstice389 year30 + 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

Implementations§

Source§

impl<const T: bool, const U: bool> Symmetry<T, U>

Source

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.

Source

pub fn new_year_day_unchecked(sym_year: i32, sym_epoch: i64) -> i64

Returns the fixed day number of a Symmetry year

Source

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> Clone for Symmetry<T, U>

Source§

fn clone(&self) -> Symmetry<T, U>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const T: bool, const U: bool> CommonWeekOfYear<SymmetryMonth> for Symmetry<T, U>

Source§

fn week_of_year(self) -> u8

Calculate the week of year for a particular date.
Source§

fn nth_kday(self, nz: NonZero<i16>, k: Weekday) -> Fixed

Find the nth occurence of a given day of the week
Source§

impl<const T: bool, const U: bool> Debug for Symmetry<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const T: bool, const U: bool> Display for Symmetry<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const T: bool, const U: bool> Epoch for Symmetry<T, U>

Source§

impl<const T: bool, const U: bool> FromFixed for Symmetry<T, U>

Source§

fn from_fixed(fixed_date: Fixed) -> Symmetry<T, U>

Source§

impl<const T: bool, const U: bool> GuaranteedMonth<SymmetryMonth> for Symmetry<T, U>

Source§

fn month(self) -> T

Source§

fn try_new(year: i32, month: T, day: u8) -> Result<Self, CalendarError>

Attempt to a date in a specific calendar system
Source§

impl<const T: bool, const U: bool> HasLeapYears for Symmetry<T, U>

Source§

fn is_leap(sym_year: i32) -> bool

true if a the given year is a leap year.
Source§

impl<const T: bool, const U: bool> PartialEq for Symmetry<T, U>

Source§

fn eq(&self, other: &Symmetry<T, U>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const T: bool, const U: bool> PartialOrd for Symmetry<T, U>

Source§

fn partial_cmp(&self, other: &Symmetry<T, U>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const T: bool, const U: bool> PresetDisplay for Symmetry<T, U>

Source§

fn supported_display_lang(lang: Language) -> bool

Checks if language is supported
Source§

fn preset_str(&self, lang: Language, preset: PresetFormat<'_>) -> String

Format a date in any PresetFormat
Source§

fn long_date(&self) -> String

Format a date in a calendar-specific long format
Source§

fn short_date(&self) -> String

Format a date in a calendar-specific short format
Source§

impl<const T: bool, const U: bool> Quarter for Symmetry<T, U>

Source§

fn quarter(self) -> NonZero<u8>

Calculate the quarter associated with a particular date. Read more
Source§

impl<const T: bool, const U: bool> ToFixed for Symmetry<T, U>

Source§

fn to_fixed(self) -> Fixed

Source§

fn convert<T: FromFixed>(self) -> T

Source§

impl<const T: bool, const U: bool> ToFromCommonDate<SymmetryMonth> for Symmetry<T, U>

Source§

fn to_common_date(self) -> CommonDate

Convert calendar date to a year, month and day
Source§

fn from_common_date_unchecked(date: CommonDate) -> Self

Convert a year, month and day into a calendar date without checking validity Read more
Source§

fn valid_ymd(date: CommonDate) -> Result<(), CalendarError>

Returns error if the year, month or day is invalid
Source§

fn year_end_date(year: i32) -> CommonDate

End of the year as a numeric year, month and day
Source§

fn year_start_date(year: i32) -> CommonDate

Start of the year as a numeric year, month and day
Source§

fn in_effective_bounds(d: CommonDate) -> bool

true if the year, month and day is within the supported range of time. Read more
Source§

fn try_from_common_date(d: CommonDate) -> Result<Self, CalendarError>

Attempt to create a date in a specific calendar from a CommonDate
Source§

fn try_year_start(year: i32) -> Result<Self, CalendarError>

Attempt to create a date in a specific calendar at the start of a specific year Read more
Source§

fn try_year_end(year: i32) -> Result<Self, CalendarError>

Attempt to create a date in a specific calendar at the end of a specific year Read more
Source§

fn day(self) -> u8

Source§

fn try_month(self) -> Option<T>

Attempt to return the month Read more
Source§

fn year(self) -> i32

Source§

impl<const T: bool, const U: bool> ToFromOrdinalDate for Symmetry<T, U>

Source§

fn valid_ordinal(ord: OrdinalDate) -> Result<(), CalendarError>

Check if the year and day of year is valid for a particular calendar system
Source§

fn ordinal_from_fixed(fixed_date: Fixed) -> OrdinalDate

Calculate the year and day of year from a Fixed.
Source§

fn to_ordinal(self) -> OrdinalDate

Calculate the year and day of year from a calendar date.
Source§

fn from_ordinal_unchecked(ord: OrdinalDate) -> Self

Convert a year and day of year into a calendar date without checking validity Read more
Source§

fn try_from_ordinal(ord: OrdinalDate) -> Result<Self, CalendarError>

Attempt to create a date in a specific calendar from an OrdinalDate
Source§

impl<const T: bool, const U: bool> AllowYearZero for Symmetry<T, U>

Source§

impl<const T: bool, const U: bool> CalculatedBounds for Symmetry<T, U>

Source§

impl<const T: bool, const U: bool> Copy for Symmetry<T, U>

Source§

impl<const T: bool, const U: bool> StructuralPartialEq for Symmetry<T, U>

Auto Trait Implementations§

§

impl<const T: bool, const U: bool> Freeze for Symmetry<T, U>

§

impl<const T: bool, const U: bool> RefUnwindSafe for Symmetry<T, U>

§

impl<const T: bool, const U: bool> Send for Symmetry<T, U>

§

impl<const T: bool, const U: bool> Sync for Symmetry<T, U>

§

impl<const T: bool, const U: bool> Unpin for Symmetry<T, U>

§

impl<const T: bool, const U: bool> UnwindSafe for Symmetry<T, U>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> EffectiveBound for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.