Struct Timestamp

Source
#[non_exhaustive]
pub struct Timestamp { /* private fields */ }
Expand description

Well-known point in time representation for Google APIs.

A Timestamp represents a point in time independent of any time zone or local calendar, encoded as a count of seconds and fractions of seconds at nanosecond resolution. The count is relative to an epoch at UTC midnight on January 1, 1970, in the proleptic Gregorian calendar which extends the Gregorian calendar backwards to year one.

All minutes are 60 seconds long. Leap seconds are “smeared” so that no leap second table is needed for interpretation, using a 24-hour linear smear.

The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By restricting to that range, we ensure that we can convert to and from RFC 3339 date strings.

§JSON Mapping

In JSON format, the Timestamp type is encoded as a string in the RFC 3339 format. That is, the format is “{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z” where {year} is always expressed using four digits while {month}, {day}, {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), are optional. The “Z” suffix indicates the timezone (“UTC”); the timezone is required.

For example, “2017-01-15T01:30:15.01Z” encodes 15.01 seconds past 01:30 UTC on January 15, 2017.

Implementations§

Source§

impl Timestamp

Source

pub const MIN_SECONDS: i64 = -62_135_596_800i64

The minimum value for the seconds component. Corresponds to ‘0001-01-01T00:00:00Z’.

Source

pub const MAX_SECONDS: i64 = 253_402_300_799i64

The maximum value for the seconds component. Corresponds to ‘9999-12-31T23:59:59Z’.

Source

pub const MIN_NANOS: i32 = 0i32

The minimum value for the nanos component.

Source

pub const MAX_NANOS: i32 = 999_999_999i32

The maximum value for the nanos component.

Source

pub fn new(seconds: i64, nanos: i32) -> Result<Self, TimestampError>

Creates a new Timestamp from the seconds and nanoseconds.

If either value is out of range it returns an error.

§Arguments
  • seconds - the seconds on the timestamp.
  • nanos - the nanoseconds on the timestamp.
Source

pub fn clamp(seconds: i64, nanos: i32) -> Self

Create a normalized, clamped Timestamp.

Timestamps must be between 0001-01-01T00:00:00Z and 9999-12-31T23:59:59.999999999Z, and the nanoseconds component must always be in the range [0, 999_999_999]. This function creates a new Timestamp instance clamped to those ranges.

The function effectively adds the nanoseconds part (with carry) to the seconds part, with saturation.

§Arguments
  • seconds - the seconds on the timestamp.
  • nanos - the nanoseconds added to the seconds.
Source

pub fn seconds(&self) -> i64

Represents seconds of UTC time since Unix epoch (1970-01-01T00:00:00Z).

Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.

Source

pub fn nanos(&self) -> i32

Non-negative fractions of a second at nanosecond resolution.

Negative second values (before the Unix epoch) with fractions must still have non-negative nanos values that count forward in time. Must be from 0 to 999,999,999 inclusive.

Trait Implementations§

Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Timestamp

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Timestamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Timestamp

Source§

fn default() -> Timestamp

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Timestamp

Implement serde deserialization for timestamps.

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Message for Timestamp

Source§

fn typename() -> &'static str

The typename of this message.
Source§

impl PartialEq for Timestamp

Source§

fn eq(&self, other: &Timestamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Timestamp

Source§

fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Timestamp

Implement serde serialization for timestamps.

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&Timestamp> for String

Converts a Timestamp to its String representation.

Source§

type Error = TimestampError

The type returned in the event of a conversion error.
Source§

fn try_from(timestamp: &Timestamp) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Timestamp

Converts the String representation of a timestamp to Timestamp.

Source§

type Error = TimestampError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for Timestamp

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,