Struct ion_rs::types::Timestamp

source ·
pub struct Timestamp { /* private fields */ }
Expand description

Represents a point in time to a specified degree of precision. Unlike chrono’s NaiveDateTime and DateTime, a Timestamp has variable precision ranging from a year to fractional seconds of an arbitrary unit.

Implementations§

source§

impl Timestamp

source

pub fn from_datetime<D>(datetime: D, precision: Precision) -> Timestampwhere D: Datelike + Timelike + Into<Timestamp>,

Converts a NaiveDateTime or DateTime<FixedOffset> to a Timestamp with the specified precision. If the precision is Precision::Second, nanosecond precision (the maximum supported by a Timelike) is assumed.

source

pub fn fractional_seconds_scale(&self) -> Option<i64>

If the precision is Precision::Second, returns the Decimal scale of this Timestamp’s fractional seconds; otherwise, returns None.

For example, a Timestamp with 553 milliseconds would return a Decimal scale of 3.

source

pub fn with_year(year: u32) -> MonthSetter

Creates a TimestampBuilder with the specified year and Precision::Year.

source

pub fn with_ymd(year: u32, month: u32, day: u32) -> HourAndMinuteSetter

Creates a TimestampBuilder with the specified year, month, and day. Its precision is set to Precision::Day.

source

pub fn with_ymd_hms( year: u32, month: u32, day: u32, hour: u32, minute: u32, second: u32 ) -> FractionalSecondSetter

Creates a TimestampBuilder with the specified year, month, day, hour, minute, and second. Its precision is set to Precision::Second.

source

pub fn with_ymd_hms_millis( year: u32, month: u32, day: u32, hour: u32, minute: u32, second: u32, milliseconds: u32 ) -> FractionalSecondSetter

Creates a TimestampBuilder with the specified year, month, day, hour, minute, second and milliseconds. Its precision is set to Precision::Second.

source

pub fn offset(&self) -> Option<i32>

Returns the offset in minutes that has been specified in the Timestamp. A positive value indicates Eastern Hemisphere, while a negative value indicates Western Hemisphere.

source

pub fn precision(&self) -> Precision

Returns the precision that has been specified in the Timestamp.

source

pub fn year(&self) -> i32

Returns the year that has been specified in the Timestamp.

source

pub fn month(&self) -> u32

Returns the month that has been specified in the Timestamp. Returns the month number starting from 1. The return value ranges from 1 to 12.

source

pub fn day(&self) -> u32

Returns the day that has been specified in the Timestamp. Returns the day of month starting from 1.

source

pub fn hour(&self) -> u32

Returns the hour(s) that has been specified in the Timestamp. Returns the hour number from 0 to 23.

source

pub fn minute(&self) -> u32

Returns the minute(s) that has been specified in the Timestamp. Returns the minute number from 0 to 59.

source

pub fn second(&self) -> u32

Returns the second(s) that has been specified in the Timestamp. Returns the second number from 0 to 59.

source

pub fn to_utc(&self) -> Timestamp

Return a UTC timestamp for this Timestamp

source

pub fn nanoseconds(&self) -> u32

Returns this Timestamp’s fractional seconds in nanoseconds

NOTE: This is a potentially lossy operation. A Timestamp with picoseconds would return a number of nanoseconds, losing precision. If it loses precision then truncation is preformed. (e.g. a timestamp with fractional seconds of 0.000000000999 would be returned as 0)

source

pub fn milliseconds(&self) -> u32

Returns this Timestamp’s fractional seconds in milliseconds

NOTE: This is a potentially lossy operation. A Timestamp with picoseconds would return a number of milliseconds, losing precision. If it loses precision then truncation is preformed. (e.g. a timestamp with fractional seconds of 0.000999 would be returned as 0)

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 Display for Timestamp

Formats an ISO-8601 timestamp of appropriate precision and offset.

source§

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

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

impl From<DateTime<FixedOffset>> for Timestamp

source§

fn from(fixed_offset_date_time: DateTime<FixedOffset>) -> Self

Converts to this type from the input type.
source§

impl From<NaiveDateTime> for Timestamp

source§

fn from(date_time: NaiveDateTime) -> Self

Converts to this type from the input type.
source§

impl From<Timestamp> for Value

source§

fn from(timestamp_val: Timestamp) -> Self

Converts to this type from the input type.
source§

impl Ord for Timestamp

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Timestamp> for Timestamp

Two Timestamps are considered equal (though not necessarily IonEq) if they represent the same instant in time. Precision is ignored. Offsets do not have to match as long as the instants being represented match. Examples:

  • 2022T == 2022T-01
  • 2022T == 2022T-01-01T00:00:00.000+00:00
  • 2022T-05-11T12:00:00.000Z == 2022T-05-11T07:00:00.000-05:00
source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Timestamp> for Timestamp

source§

fn partial_cmp(&self, other: &Self) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryInto<DateTime<FixedOffset>> for Timestamp

§

type Error = IonError

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

fn try_into(self) -> Result<DateTime<FixedOffset>, Self::Error>

Performs the conversion.
source§

impl TryInto<NaiveDateTime> for Timestamp

§

type Error = IonError

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

fn try_into(self) -> Result<NaiveDateTime, Self::Error>

Performs the conversion.
source§

impl Eq for Timestamp

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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<V> IntoAnnotatedElement for Vwhere V: Into<Value>,

source§

fn with_annotations<I: IntoAnnotations>(self, annotations: I) -> Element

Converts the value into an Element with the specified annotations.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.