pub struct Timestamp { /* private fields */ }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.
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.
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 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
Sourcepub const fn sunday_based_week(self) -> u8
pub const fn sunday_based_week(self) -> u8
Get the Sunday-based week number of the timestamp in UTC.
The returned value will always be in the range 0..=53.
Sourcepub const fn monday_based_week(self) -> u8
pub const fn monday_based_week(self) -> u8
Get the Monday-based week number of the timestamp in UTC.
The returned value will always be in the range 0..=53.
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
Get the Julian day of the timestamp.
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
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.
Source§impl Timestamp
impl Timestamp
Sourcepub fn format_into(
self,
output: &mut (impl Write + ?Sized),
format: &(impl Formattable + ?Sized),
) -> Result<usize, Format>
Available on crate feature formatting only.
pub fn format_into( self, output: &mut (impl Write + ?Sized), format: &(impl Formattable + ?Sized), ) -> Result<usize, Format>
formatting only.Format the Timestamp using the provided format description.
Sourcepub fn format(
self,
format: &(impl Formattable + ?Sized),
) -> Result<String, Format>
Available on crate feature formatting only.
pub fn format( self, format: &(impl Formattable + ?Sized), ) -> Result<String, Format>
formatting only.Format the Timestamp using the provided format description.
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.
impl Copy for Timestamp
Source§impl<'a> Deserialize<'a> for Timestamp
Available on crate feature serde only.
impl<'a> Deserialize<'a> for Timestamp
serde only.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 Distribution<Timestamp> for StandardUniform
Available on crate feature rand010 only.
impl Distribution<Timestamp> for StandardUniform
rand010 only.Source§fn sample<R>(&self, rng: &mut R) -> Timestampwhere
R: Rng + ?Sized,
fn sample<R>(&self, rng: &mut R) -> Timestampwhere
R: Rng + ?Sized,
T, using rng as the source of randomness.§fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>where
R: Rng,
Self: Sized,
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>where
R: Rng,
Self: Sized,
T, using rng as
the source of randomness. Read moreSource§impl Distribution<Timestamp> for Standard
Available on crate feature rand08 only.
impl Distribution<Timestamp> for Standard
rand08 only.Source§impl Distribution<Timestamp> for StandardUniform
Available on crate feature rand09 only.
impl Distribution<Timestamp> for StandardUniform
rand09 only.impl Eq for Timestamp
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
Available on crate feature std only.
impl From<SystemTime> for Timestamp
std only.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
Available on crate feature std only.
impl From<Timestamp> for SystemTime
std only.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
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<OffsetDateTime> for Timestamp
impl PartialEq<OffsetDateTime> for Timestamp
Source§fn eq(&self, other: &OffsetDateTime) -> bool
fn eq(&self, other: &OffsetDateTime) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<SystemTime> for Timestamp
Available on crate feature std only.
impl PartialEq<SystemTime> for Timestamp
std only.Source§fn eq(&self, other: &SystemTime) -> bool
fn eq(&self, other: &SystemTime) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<Timestamp> for OffsetDateTime
impl PartialEq<Timestamp> for OffsetDateTime
Source§impl PartialEq<Timestamp> for SystemTime
Available on crate feature std only.
impl PartialEq<Timestamp> for SystemTime
std only.Source§impl PartialEq<Timestamp> for UtcDateTime
impl PartialEq<Timestamp> for UtcDateTime
Source§impl PartialEq<UtcDateTime> for Timestamp
impl PartialEq<UtcDateTime> for Timestamp
Source§fn eq(&self, other: &UtcDateTime) -> bool
fn eq(&self, other: &UtcDateTime) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl PartialOrd<OffsetDateTime> for Timestamp
impl PartialOrd<OffsetDateTime> for Timestamp
Source§impl PartialOrd<SystemTime> for Timestamp
Available on crate feature std only.
impl PartialOrd<SystemTime> for Timestamp
std only.Source§impl PartialOrd<Timestamp> for OffsetDateTime
impl PartialOrd<Timestamp> for OffsetDateTime
Source§impl PartialOrd<Timestamp> for SystemTime
Available on crate feature std only.
impl PartialOrd<Timestamp> for SystemTime
std only.Source§impl PartialOrd<Timestamp> for UtcDateTime
impl PartialOrd<Timestamp> for UtcDateTime
Source§impl PartialOrd<UtcDateTime> for Timestamp
impl PartialOrd<UtcDateTime> for Timestamp
Source§impl Sub<OffsetDateTime> for Timestamp
impl Sub<OffsetDateTime> for Timestamp
Source§impl Sub<SystemTime> for Timestamp
Available on crate feature std only.
impl Sub<SystemTime> for Timestamp
std only.Source§impl Sub<Timestamp> for OffsetDateTime
impl Sub<Timestamp> for OffsetDateTime
Source§impl Sub<Timestamp> for SystemTime
Available on crate feature std only.
impl Sub<Timestamp> for SystemTime
std only.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.