pub struct Date { /* private fields */ }Expand description
A date value (days since 2000-01-01).
Hyper uses 2000-01-01 as the epoch, which is different from Unix epoch.
Implementations§
Source§impl Date
impl Date
Sourcepub const EPOCH_YEAR: i32 = 2000
pub const EPOCH_YEAR: i32 = 2000
The Hyper epoch year: 2000
Sourcepub const EPOCH_MONTH: u32 = 1
pub const EPOCH_MONTH: u32 = 1
The Hyper epoch month: 1 (January)
Sourcepub const JULIAN_DAY_EPOCH: i32 = 2451545
pub const JULIAN_DAY_EPOCH: i32 = 2451545
Julian Day Number for 2000-01-01 (the Hyper epoch)
Sourcepub const MAX_DAYS: i32
pub const MAX_DAYS: i32
Maximum supported days offset (year 9999, Dec 31 relative to 2000-01-01).
Sourcepub const MIN_JULIAN_DAY: i32 = 1721060
pub const MIN_JULIAN_DAY: i32 = 1721060
Minimum supported Julian day (year 1, Jan 1)
Sourcepub const MAX_JULIAN_DAY: i32 = 5373484
pub const MAX_JULIAN_DAY: i32 = 5373484
Maximum supported Julian day (year 9999, Dec 31)
Sourcepub const fn from_days(days: i32) -> Date
pub const fn from_days(days: i32) -> Date
Creates a Date from days since epoch.
No validation is performed. For a checked variant, use try_from_days.
Sourcepub const fn encode(&self) -> u32
pub const fn encode(&self) -> u32
Returns the raw encoded value for HyperBinary (Julian Day Number).
Uses wrapping arithmetic to avoid panic for out-of-range days values. Callers should validate dates are within supported range (years 1-9999) before relying on the encoded value.
Sourcepub const fn decode(encoded: u32) -> Date
pub const fn decode(encoded: u32) -> Date
Creates a Date from a raw encoded value (Julian Day Number).
This is an infallible version that does not validate the date range.
Use try_decode for validation.
Sourcepub fn try_decode(encoded: u32) -> Result<Date, Box<dyn Error + Sync + Send>>
pub fn try_decode(encoded: u32) -> Result<Date, Box<dyn Error + Sync + Send>>
Creates a Date from a raw encoded value (Julian Day Number) with validation.
Returns an error if the date is outside the supported range (years 1-9999) or if the calculation would overflow.
§Examples
use hyperdb_api_core::types::Date;
// Valid date
let date = Date::try_decode(2451545).unwrap(); // 2000-01-01
// Invalid date (out of range)
assert!(Date::try_decode(0).is_err());§Errors
- Returns an error if
encoded(reinterpreted asi32) falls outside the supported Julian day rangeSelf::MIN_JULIAN_DAY..=Self::MAX_JULIAN_DAY(years 1-9999). - Returns an error if the day offset from the epoch would overflow
i32or exceedi32::MAX / 2.
Sourcepub const fn to_julian_day(&self) -> i32
pub const fn to_julian_day(&self) -> i32
Returns the Julian Day Number for this date.
Hyper stores dates as Julian Day Numbers (absolute day count).
Uses wrapping arithmetic to avoid panic for out-of-range days values. Callers should validate dates are within supported range (years 1-9999) before relying on the Julian day value.
Trait Implementations§
Source§impl FromBinaryValue for Date
impl FromBinaryValue for Date
Source§impl FromHyperBinary for Date
impl FromHyperBinary for Date
Source§impl ToHyperBinary for Date
impl ToHyperBinary for Date
Source§fn to_hyper_binary(
&self,
buf: &mut BytesMut,
) -> Result<(), Box<dyn Error + Sync + Send>>
fn to_hyper_binary( &self, buf: &mut BytesMut, ) -> Result<(), Box<dyn Error + Sync + Send>>
Source§fn to_hyper_binary_not_null(
&self,
buf: &mut BytesMut,
) -> Result<(), Box<dyn Error + Sync + Send>>
fn to_hyper_binary_not_null( &self, buf: &mut BytesMut, ) -> Result<(), Box<dyn Error + Sync + Send>>
Source§fn hyper_binary_size(&self) -> usize
fn hyper_binary_size(&self) -> usize
Source§fn hyper_binary_size_not_null(&self) -> usize
fn hyper_binary_size_not_null(&self) -> usize
Source§impl ToSqlParam for Date
impl ToSqlParam for Date
impl Copy for Date
impl Eq for Date
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnsafeUnpin for Date
impl UnwindSafe for Date
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> 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request