pub struct CalendarDate { /* private fields */ }Expand description
A calendar day, which is the only temporal resolution a rate table has.
Deliberately not a dependency. cargo tree shows time 0.3 in this workspace,
but only as a transitive dependency of aws-smithy-runtime — taking it here
would mean adding a direct dependency, and the module needs exactly two
operations: pin a retrieval date, and subtract two dates to get an age in days.
No parsing, no formatting, no zones, no arithmetic on months. So the whole date
surface is the proleptic-Gregorian day number below, which is twelve lines and
has a pinned test against three known values.
Implementations§
Source§impl CalendarDate
impl CalendarDate
Sourcepub const fn from_ymd(year: i32, month: u32, day: u32) -> CalendarDate
pub const fn from_ymd(year: i32, month: u32, day: u32) -> CalendarDate
A date from its parts, for the literals in this file.
const so pinned_rates can pin its retrieval date, which is also why it does
not validate: a const fn cannot return a Result a caller must handle at
compile time. The literals it is used on are pinned by
the_pinned_dates_are_real_calendar_days; anything arriving at runtime goes
through CalendarDate::try_from_ymd.
Sourcepub fn try_from_ymd(
year: i32,
month: u32,
day: u32,
) -> Result<CalendarDate, Error>
pub fn try_from_ymd( year: i32, month: u32, day: u32, ) -> Result<CalendarDate, Error>
A date from parts that came from outside this crate.
The S2 boundary: a --today flag or a JSON field is three integers, and
2026-02-30 would otherwise produce a day number for March 2nd and an age
two days out.
Sourcepub fn today_utc() -> CalendarDate
pub fn today_utc() -> CalendarDate
Today, UTC.
UTC rather than local, and no dependency: a rate table’s age is measured in
ninety-day units, so the zone can only ever move the answer by a day and
carrying a timezone database to decide it would be absurd. Falls back to the
epoch if the clock is set before 1970, which is a machine whose age
arithmetic is already meaningless and is not worth a Result on every
report.
pub fn year(self) -> i32
pub fn month(self) -> u32
pub fn day(self) -> u32
Sourcepub fn day_number(self) -> i64
pub fn day_number(self) -> i64
Days since 1970-01-01, negative before it.
Howard Hinnant’s days_from_civil, which is the algorithm every date library
uses: it shifts the year to start in March so the leap day lands at the end
of a year and the month-length pattern becomes the linear (153m + 2) / 5.
Correct for every proleptic-Gregorian date, and pinned below against
1970-01-01, a leap day, and this table’s own retrieval date.
Sourcepub fn days_since(self, earlier: CalendarDate) -> i64
pub fn days_since(self, earlier: CalendarDate) -> i64
Days from earlier to self, negative when self is the earlier one.
Trait Implementations§
Source§impl Clone for CalendarDate
impl Clone for CalendarDate
Source§fn clone(&self) -> CalendarDate
fn clone(&self) -> CalendarDate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CalendarDate
Source§impl Debug for CalendarDate
impl Debug for CalendarDate
Source§impl Display for CalendarDate
ISO 8601, because that is what the Python client’s retrieved.isoformat() puts
in the report header and the two have to be diffable.
impl Display for CalendarDate
ISO 8601, because that is what the Python client’s retrieved.isoformat() puts
in the report header and the two have to be diffable.
impl Eq for CalendarDate
Source§impl Hash for CalendarDate
impl Hash for CalendarDate
Source§impl Ord for CalendarDate
impl Ord for CalendarDate
Source§fn cmp(&self, other: &CalendarDate) -> Ordering
fn cmp(&self, other: &CalendarDate) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for CalendarDate
impl PartialEq for CalendarDate
Source§impl PartialOrd for CalendarDate
impl PartialOrd for CalendarDate
impl StructuralPartialEq for CalendarDate
Auto Trait Implementations§
impl Freeze for CalendarDate
impl RefUnwindSafe for CalendarDate
impl Send for CalendarDate
impl Sync for CalendarDate
impl Unpin for CalendarDate
impl UnsafeUnpin for CalendarDate
impl UnwindSafe for CalendarDate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more