#[repr(C)]pub struct Timestamp {
padding: Padding,
nanoseconds: ru32<0, 999_999_999>,
seconds: ri64<{ _ }, { _ }>,
}Expand description
A Unix timestamp with nanosecond precision.
This type represents a point in time as a number of seconds and nanoseconds elapsed since the Unix epoch (1970-01-01 00:00:00 UTC). Negative values represent times before the Unix epoch.
Fields§
§padding: Padding§nanoseconds: ru32<0, 999_999_999>§seconds: ri64<{ _ }, { _ }>Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
A Timestamp representing the Unix epoch (1970-01-01 00:00:00 UTC).
Sourcepub const MIN: Self
pub const MIN: Self
The minimum valid Timestamp.
The moment in time represented by this value may vary depending on the feature flags enabled.
Sourcepub const MAX: Self
pub const MAX: Self
The maximum valid Timestamp.
The moment in time represented by this value may vary depending on the feature flags enabled.
const fn as_i128(self) -> i128
Sourcepub(crate) const fn new_ranged(
seconds: ri64<{ _ }, { _ }>,
nanoseconds: ru32<0, 999_999_999>,
) -> Self
pub(crate) const fn new_ranged( seconds: ri64<{ _ }, { _ }>, nanoseconds: ru32<0, 999_999_999>, ) -> Self
Create a Timestamp from the provided seconds and nanoseconds values that are known to be
in range.
Sourcepub const fn from_seconds(seconds: i64) -> Result<Self, ComponentRange>
pub const fn from_seconds(seconds: i64) -> Result<Self, ComponentRange>
Sourcepub const fn from_milliseconds(
milliseconds: i64,
) -> Result<Self, ComponentRange>
pub const fn from_milliseconds( milliseconds: i64, ) -> Result<Self, ComponentRange>
Sourcepub const fn from_microseconds(
microseconds: i128,
) -> Result<Self, ComponentRange>
pub const fn from_microseconds( microseconds: i128, ) -> Result<Self, ComponentRange>
Sourcepub const fn from_nanoseconds(nanoseconds: i128) -> Result<Self, ComponentRange>
pub const fn from_nanoseconds(nanoseconds: i128) -> Result<Self, ComponentRange>
Sourcepub const fn to_offset(self, offset: UtcOffset) -> OffsetDateTime
pub const fn to_offset(self, offset: UtcOffset) -> OffsetDateTime
Convert the Timestamp to an OffsetDateTime at the provided offset.
§Panics
This panics if the resulting date-time with the provided offset is outside the supported
range. Consider using checked_to_offset for a non-panicking
alternative.
Sourcepub const fn checked_to_offset(
self,
offset: UtcOffset,
) -> Option<OffsetDateTime>
pub const fn checked_to_offset( self, offset: UtcOffset, ) -> Option<OffsetDateTime>
Convert the Timestamp to an OffsetDateTime with the provided offset, returning None
if the resulting value is out of range.
Sourcepub const fn to_utc(self) -> UtcDateTime
pub const fn to_utc(self) -> UtcDateTime
Convert the Timestamp to a UtcDateTime.
Sourcepub(crate) const fn as_parts_ranged(
self,
) -> (ri64<{ _ }, { _ }>, ru32<0, 999_999_999>)
pub(crate) const fn as_parts_ranged( self, ) -> (ri64<{ _ }, { _ }>, ru32<0, 999_999_999>)
Get the seconds and nanoseconds of the timestamp as ranged values.
Sourcepub const fn as_seconds(self) -> i64
pub const fn as_seconds(self) -> i64
Sourcepub const fn as_milliseconds(self) -> i64
pub const fn as_milliseconds(self) -> i64
Sourcepub const fn as_microseconds(self) -> i128
pub const fn as_microseconds(self) -> i128
Sourcepub const fn as_nanoseconds(self) -> i128
pub const fn as_nanoseconds(self) -> i128
Sourceconst fn year_leap_ordinal(self) -> (i32, bool, u16)
const fn year_leap_ordinal(self) -> (i32, bool, u16)
Compute the year, leap year status, and ordinal day of the timestamp in UTC.
This algorithm is essentially identical to Date::from_julian_day_unchecked. Instead of
returning Date, it returns the components as a tuple. By not bitpacking the values, it
allows the compiler to see through the function boundary and better optimize methods.
Sourcepub const fn sunday_based_week(self) -> u8
pub const fn sunday_based_week(self) -> u8
Sourcepub const fn monday_based_week(self) -> u8
pub const fn monday_based_week(self) -> u8
Sourcepub const fn to_calendar_date(self) -> (i32, Month, u8)
pub const fn to_calendar_date(self) -> (i32, Month, u8)
Sourcepub const fn to_ordinal_date(self) -> (i32, u16)
pub const fn to_ordinal_date(self) -> (i32, u16)
Sourcepub const fn to_iso_week_date(self) -> (i32, u8, Weekday)
pub const fn to_iso_week_date(self) -> (i32, u8, Weekday)
Sourcepub const fn to_julian_day(self) -> i32
pub const fn to_julian_day(self) -> i32
Sourcepub const fn millisecond(self) -> u16
pub const fn millisecond(self) -> u16
Sourcepub const fn microsecond(self) -> u32
pub const fn microsecond(self) -> u32
Sourcepub const fn nanosecond(self) -> u32
pub const fn nanosecond(self) -> u32
Sourceconst fn add(self, duration: Duration) -> Result<Self, Overflow>
const fn add(self, duration: Duration) -> Result<Self, Overflow>
Add a Duration to the timestamp. Returns Overflow::Positive or Overflow::Negative if
the result is out of range.
Sourceconst fn sub(self, duration: Duration) -> Result<Self, Overflow>
const fn sub(self, duration: Duration) -> Result<Self, Overflow>
Subtract a Duration from the timestamp. Returns Overflow::Positive or
Overflow::Negative if the result is out of range.
Sourceconst fn add_std(self, duration: StdDuration) -> Result<Self, Overflow>
const fn add_std(self, duration: StdDuration) -> Result<Self, Overflow>
Add a std::time::Duration to the timestamp. Returns Overflow::Positive or
Overflow::Negative if the result is out of range.
Sourceconst fn sub_std(self, duration: StdDuration) -> Result<Self, Overflow>
const fn sub_std(self, duration: StdDuration) -> Result<Self, Overflow>
Subtract a std::time::Duration from the timestamp. Returns Overflow::Positive or
Overflow::Negative if the result is out of range.
Sourcepub const fn checked_add(self, duration: Duration) -> Option<Self>
pub const fn checked_add(self, duration: Duration) -> Option<Self>
Checked addition of a Duration, returning None if the result is out of range.
Sourcepub const fn checked_sub(self, duration: Duration) -> Option<Self>
pub const fn checked_sub(self, duration: Duration) -> Option<Self>
Checked subtraction of a Duration, returning None if the result is out of range.
Sourcepub const fn saturating_add(self, duration: Duration) -> Self
pub const fn saturating_add(self, duration: Duration) -> Self
Saturating addition of a Duration.
Returns Timestamp::MAX or Timestamp::MIN if the result is out of range.
Sourcepub const fn saturating_sub(self, duration: Duration) -> Self
pub const fn saturating_sub(self, duration: Duration) -> Self
Saturating subtraction of a Duration.
Returns Timestamp::MAX or Timestamp::MIN if the result is out of range.
Source§impl Timestamp
Methods that replace part of the Timestamp.
impl Timestamp
Methods that replace part of the Timestamp.
Sourcepub const fn replace_time(self, time: Time) -> Self
pub const fn replace_time(self, time: Time) -> Self
Sourcepub const fn replace_date(self, date: Date) -> Self
pub const fn replace_date(self, date: Date) -> Self
Sourcepub const fn replace_year(self, year: i32) -> Result<Self, ComponentRange>
pub const fn replace_year(self, year: i32) -> Result<Self, ComponentRange>
Replace the year, preserving the month and day. If the date is February 29 and the resulting year is not a leap year, an error is returned.
Sourcepub const fn replace_month(self, month: Month) -> Result<Self, ComponentRange>
pub const fn replace_month(self, month: Month) -> Result<Self, ComponentRange>
Replace the month of the year, preserving the year and day. If the day is invalid for the resulting month, an error is returned.
Sourcepub const fn replace_day(self, day: u8) -> Result<Self, ComponentRange>
pub const fn replace_day(self, day: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_ordinal(self, ordinal: u16) -> Result<Self, ComponentRange>
pub const fn replace_ordinal(self, ordinal: u16) -> Result<Self, ComponentRange>
Replace the day of the year.
assert_eq!(
timestamp!(1_546_398_245).replace_ordinal(1),
Ok(timestamp!(1_546_311_845))
);
assert!(timestamp!(1_546_398_245).replace_ordinal(0).is_err()); // 0 isn't a valid day of the year
assert!(timestamp!(1_546_398_245).replace_ordinal(366).is_err()); // the timestamp is in 2019, which isn't a leap yearSourcepub const fn replace_hour(self, hour: u8) -> Result<Self, ComponentRange>
pub const fn replace_hour(self, hour: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_minute(self, minute: u8) -> Result<Self, ComponentRange>
pub const fn replace_minute(self, minute: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_second(self, second: u8) -> Result<Self, ComponentRange>
pub const fn replace_second(self, second: u8) -> Result<Self, ComponentRange>
Sourcepub const fn replace_millisecond(
self,
millisecond: u16,
) -> Result<Self, ComponentRange>
pub const fn replace_millisecond( self, millisecond: u16, ) -> Result<Self, ComponentRange>
Sourcepub const fn replace_microsecond(
self,
microsecond: u32,
) -> Result<Self, ComponentRange>
pub const fn replace_microsecond( self, microsecond: u32, ) -> Result<Self, ComponentRange>
Sourcepub const fn replace_nanosecond(
self,
nanosecond: u32,
) -> Result<Self, ComponentRange>
pub const fn replace_nanosecond( self, nanosecond: u32, ) -> Result<Self, ComponentRange>
Replace the nanoseconds within the second.
Sourceconst fn replace_nanosecond_ranged(
self,
new_nanos: ru32<0, 999_999_999>,
) -> Self
const fn replace_nanosecond_ranged( self, new_nanos: ru32<0, 999_999_999>, ) -> Self
Replace the nanoseconds within the second using a range-bounded integer to avoid range checks.
Source§impl Timestamp
impl Timestamp
Sourcepub fn format_into(
self,
output: &mut (impl Write + ?Sized),
format: &(impl Formattable + ?Sized),
) -> Result<usize, Format>
pub fn format_into( self, output: &mut (impl Write + ?Sized), format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>
Format the Timestamp using the provided format description.
Sourcepub fn format(
self,
format: &(impl Formattable + ?Sized),
) -> Result<String, Format>
pub fn format( self, format: &(impl Formattable + ?Sized), ) -> Result<String, Format>
Format the Timestamp using the provided format description.
Source§impl Timestamp
impl Timestamp
Sourcepub fn parse(
input: &str,
description: &(impl Parsable + ?Sized),
) -> Result<Self, Parse>
pub fn parse( input: &str, description: &(impl Parsable + ?Sized), ) -> Result<Self, Parse>
Parse a Timestamp from the input using the provided format
description.
Sourcepub fn parse_with_defaults(
input: &[u8],
description: &(impl Parsable + ?Sized),
defaults: Parsed,
) -> Result<Self, Parse>
pub fn parse_with_defaults( input: &[u8], description: &(impl Parsable + ?Sized), defaults: Parsed, ) -> Result<Self, Parse>
Parse a Timestamp from the input using the provided format
description and default values.
Source§impl Timestamp
impl Timestamp
Sourceconst DISPLAY_BUFFER_SIZE: usize = 25
const DISPLAY_BUFFER_SIZE: usize = 25
The maximum number of bytes that the fmt_into_buffer method will write, which is also used
by the Display implementation.
Sourcepub(crate) fn fmt_into_buffer(self, buf: &mut [MaybeUninit<u8>; 25]) -> usize
pub(crate) fn fmt_into_buffer(self, buf: &mut [MaybeUninit<u8>; 25]) -> usize
Format the Timestamp into the provided buffer, returning the number of bytes written.
Trait Implementations§
Source§impl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
§Panics
This may panic if an overflow occurs.
Source§impl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
Source§fn add_assign(&mut self, rhs: StdDuration)
fn add_assign(&mut self, rhs: StdDuration)
§Panics
This may panic if an overflow occurs.
Source§impl ComponentProvider for Timestamp
impl ComponentProvider for Timestamp
Source§const SUPPLIES_DATE: bool = true
const SUPPLIES_DATE: bool = true
Source§const SUPPLIES_TIME: bool = true
const SUPPLIES_TIME: bool = true
Source§const SUPPLIES_OFFSET: bool = true
const SUPPLIES_OFFSET: bool = true
Source§const SUPPLIES_TIMESTAMP: bool = true
const SUPPLIES_TIMESTAMP: bool = true
Source§type State = TimestampState
type State = TimestampState
Source§fn ordinal(&self, state: &mut Self::State) -> ru16<1, 366>
fn ordinal(&self, state: &mut Self::State) -> ru16<1, 366>
Source§fn iso_week_number(&self, state: &mut Self::State) -> ru8<1, 53>
fn iso_week_number(&self, state: &mut Self::State) -> ru8<1, 53>
Source§fn monday_based_week(&self, state: &mut Self::State) -> ru8<0, 53>
fn monday_based_week(&self, state: &mut Self::State) -> ru8<0, 53>
Source§fn sunday_based_week(&self, state: &mut Self::State) -> ru8<0, 53>
fn sunday_based_week(&self, state: &mut Self::State) -> ru8<0, 53>
Source§fn calendar_year(&self, state: &mut Self::State) -> ri32<-999_999, 999_999>
fn calendar_year(&self, state: &mut Self::State) -> ri32<-999_999, 999_999>
Source§fn iso_year(&self, state: &mut Self::State) -> ri32<-999_999, 999_999>
fn iso_year(&self, state: &mut Self::State) -> ri32<-999_999, 999_999>
Source§fn second(&self, state: &mut Self::State) -> ru8<0, { _ }>
fn second(&self, state: &mut Self::State) -> ru8<0, { _ }>
Source§fn nanosecond(&self, _: &mut Self::State) -> ru32<0, { _ }>
fn nanosecond(&self, _: &mut Self::State) -> ru32<0, { _ }>
Source§fn offset_is_negative(&self, _: &mut Self::State) -> bool
fn offset_is_negative(&self, _: &mut Self::State) -> bool
Source§fn offset_is_utc(&self, _: &mut Self::State) -> bool
fn offset_is_utc(&self, _: &mut Self::State) -> bool
Source§fn offset_hour(&self, _: &mut Self::State) -> ri8<-25, 25>
fn offset_hour(&self, _: &mut Self::State) -> ri8<-25, 25>
Source§fn offset_minute(&self, _: &mut Self::State) -> ri8<{ _ }, { _ }>
fn offset_minute(&self, _: &mut Self::State) -> ri8<{ _ }, { _ }>
Source§fn offset_second(&self, _: &mut Self::State) -> ri8<{ _ }, { _ }>
fn offset_second(&self, _: &mut Self::State) -> ri8<{ _ }, { _ }>
Source§fn unix_timestamp_seconds(&self, _: &mut Self::State) -> i64
fn unix_timestamp_seconds(&self, _: &mut Self::State) -> i64
Source§fn unix_timestamp_milliseconds(&self, _: &mut Self::State) -> i64
fn unix_timestamp_milliseconds(&self, _: &mut Self::State) -> i64
Source§fn unix_timestamp_microseconds(&self, _: &mut Self::State) -> i128
fn unix_timestamp_microseconds(&self, _: &mut Self::State) -> i128
Source§fn unix_timestamp_nanoseconds(&self, _: &mut Self::State) -> i128
fn unix_timestamp_nanoseconds(&self, _: &mut Self::State) -> i128
Source§impl<'a> Deserialize<'a> for Timestamp
impl<'a> Deserialize<'a> for Timestamp
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'a>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'a>,
Source§impl From<OffsetDateTime> for Timestamp
impl From<OffsetDateTime> for Timestamp
Source§fn from(datetime: OffsetDateTime) -> Self
fn from(datetime: OffsetDateTime) -> Self
§Panics
This may panic if an overflow occurs.
Source§impl From<SystemTime> for Timestamp
impl From<SystemTime> for Timestamp
Source§fn from(datetime: SystemTime) -> Self
fn from(datetime: SystemTime) -> Self
§Panics
This may panic if an overflow occurs.
Source§impl From<Timestamp> for OffsetDateTime
impl From<Timestamp> for OffsetDateTime
Source§impl From<Timestamp> for SystemTime
impl From<Timestamp> for SystemTime
Source§impl From<Timestamp> for UtcDateTime
impl From<Timestamp> for UtcDateTime
Source§impl From<UtcDateTime> for Timestamp
impl From<UtcDateTime> for Timestamp
Source§fn from(datetime: UtcDateTime) -> Self
fn from(datetime: UtcDateTime) -> Self
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialEq<OffsetDateTime> for Timestamp
impl PartialEq<OffsetDateTime> for Timestamp
Source§impl PartialEq<SystemTime> for Timestamp
impl PartialEq<SystemTime> for Timestamp
Source§impl PartialEq<Timestamp> for OffsetDateTime
impl PartialEq<Timestamp> for OffsetDateTime
Source§impl PartialEq<Timestamp> for SystemTime
impl PartialEq<Timestamp> for SystemTime
Source§impl PartialEq<Timestamp> for UtcDateTime
impl PartialEq<Timestamp> for UtcDateTime
Source§impl PartialEq<UtcDateTime> for Timestamp
impl PartialEq<UtcDateTime> for Timestamp
Source§impl PartialOrd<OffsetDateTime> for Timestamp
impl PartialOrd<OffsetDateTime> for Timestamp
Source§impl PartialOrd<SystemTime> for Timestamp
impl PartialOrd<SystemTime> for Timestamp
Source§impl PartialOrd<Timestamp> for OffsetDateTime
impl PartialOrd<Timestamp> for OffsetDateTime
Source§impl PartialOrd<Timestamp> for SystemTime
impl PartialOrd<Timestamp> for SystemTime
Source§impl PartialOrd<Timestamp> for UtcDateTime
impl PartialOrd<Timestamp> for UtcDateTime
Source§impl PartialOrd<UtcDateTime> for Timestamp
impl PartialOrd<UtcDateTime> for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl Sub<OffsetDateTime> for Timestamp
impl Sub<OffsetDateTime> for Timestamp
Source§impl Sub<SystemTime> for Timestamp
impl Sub<SystemTime> for Timestamp
Source§impl Sub<Timestamp> for OffsetDateTime
impl Sub<Timestamp> for OffsetDateTime
Source§impl Sub<Timestamp> for SystemTime
impl Sub<Timestamp> for SystemTime
Source§impl Sub<Timestamp> for UtcDateTime
impl Sub<Timestamp> for UtcDateTime
Source§impl Sub<UtcDateTime> for Timestamp
impl Sub<UtcDateTime> for Timestamp
Source§impl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
§Panics
This may panic if an overflow occurs.
Source§impl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
Source§fn sub_assign(&mut self, rhs: StdDuration)
fn sub_assign(&mut self, rhs: StdDuration)
§Panics
This may panic if an overflow occurs.