pub struct Year(/* private fields */);Expand description
SAC13 year. It roughly corresponds to the Gregorian Year + 10’000. Roughly, because the Gregorian Calendar starts its year with January and SAC13 with March.
The year can have any value from 0 to 25’999 (both inclusive).
§Examples
use sac13::prelude::*;
// Preferred method for hard-coded / compile-time years:
let year = year!(M024);
// From &str (e.g. user input):
let year = Year::try_from_str("M024").unwrap();
// From an integer (via `TryFrom` trait):
let year = Year::new(12_024).unwrap();
// Year construction via const compile-time helper function:
// Prefer that method if you know the year at compile-time.
TODO: year construction only via TryFrom?
§About the limits
Even though the SAC13 calendar system design could easily support negative years and years beyond 26’000 we intentionally chose not to for the following reasons:
-
The 10’000 year offset compared to the Gregorian Calendar the year zero is so far in the past, there aren’t really any applications for exact dates around that time. Maybe astronomers, but they already use linear time-scales like JDN instead of civil calendars.
-
The year 25’999 is so far in the future it’s highly unlikely, that this calendar would survive unaltered for that long anyway. I hope that humans (or our AI overlords) are no longer interested in Earth-based solar calendars at that point.
-
SAC13 years are typically written with a millennium indicator letter (A=0, B=1, …, Z=25) to disambiguate between SAC13 and the Gregorian Calendar. So the year 12’020 is written as M020 and the year 25’999 would be Z999.
All SAC13 implementations have to respect those limits and handle edge cases accordingly. Having different limits than zero and 25’999 is considered a bug. Limits should be handled as graceful as possible.
For example:
- If you have a UI, prevent the user from switching to dates outside the limit.
- If you process data, or handle requests, return an error if the request contains invalid dates (dates outside the limits are invalid!).
- As a last resort you can also log, silently drop or abort the process in those cases.
The benefit of such strict rules is that everybody knows what to expect and what other systems consider valid or invalid. Unlike with the Gregorian Calender where everybody decides for themselves what the limits are. Because of that, every software out there handles the cases differently on arbitrary limits.
If you are implementing SAC13 according to the specification you know for a fact that using a 16 bit integer (signed or unsigned doesn’t matter) would be enough.
Implementations§
Source§impl Year
impl Year
Source§impl Year
impl Year
Sourcepub const fn try_from_str(year: &str) -> Option<Self>
pub const fn try_from_str(year: &str) -> Option<Self>
Used internally for the year!() macro.
TODO: details
Sourcepub const fn year_type(&self) -> YearType
pub const fn year_type(&self) -> YearType
Returns the type of the year (leap year or common year).