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
impl Timestamp
sourcepub fn from_datetime<D>(datetime: D, precision: Precision) -> Timestampwhere
D: Datelike + Timelike + Into<Timestamp>,
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.
sourcepub fn fractional_seconds_scale(&self) -> Option<i64>
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.
sourcepub fn with_year(year: u32) -> MonthSetter
pub fn with_year(year: u32) -> MonthSetter
Creates a TimestampBuilder with the specified year and Precision::Year.
sourcepub fn with_ymd(year: u32, month: u32, day: u32) -> HourAndMinuteSetter
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.
sourcepub fn with_ymd_hms(
year: u32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32
) -> FractionalSecondSetter
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.
sourcepub fn with_ymd_hms_millis(
year: u32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32,
milliseconds: u32
) -> FractionalSecondSetter
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.
sourcepub fn offset(&self) -> Option<i32>
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.
sourcepub fn precision(&self) -> Precision
pub fn precision(&self) -> Precision
Returns the precision that has been specified in the Timestamp.
sourcepub fn month(&self) -> u32
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.
sourcepub fn day(&self) -> u32
pub fn day(&self) -> u32
Returns the day that has been specified in the Timestamp. Returns the day of month starting from 1.
sourcepub fn hour(&self) -> u32
pub fn hour(&self) -> u32
Returns the hour(s) that has been specified in the Timestamp. Returns the hour number from 0 to 23.
sourcepub fn minute(&self) -> u32
pub fn minute(&self) -> u32
Returns the minute(s) that has been specified in the Timestamp. Returns the minute number from 0 to 59.
sourcepub fn second(&self) -> u32
pub fn second(&self) -> u32
Returns the second(s) that has been specified in the Timestamp. Returns the second number from 0 to 59.
sourcepub fn nanoseconds(&self) -> u32
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
)
sourcepub fn milliseconds(&self) -> u32
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 From<DateTime<FixedOffset>> for Timestamp
impl From<DateTime<FixedOffset>> for Timestamp
source§fn from(fixed_offset_date_time: DateTime<FixedOffset>) -> Self
fn from(fixed_offset_date_time: DateTime<FixedOffset>) -> Self
source§impl From<NaiveDateTime> for Timestamp
impl From<NaiveDateTime> for Timestamp
source§fn from(date_time: NaiveDateTime) -> Self
fn from(date_time: NaiveDateTime) -> Self
source§impl Ord for Timestamp
impl Ord for Timestamp
source§impl PartialEq<Timestamp> for Timestamp
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§impl PartialOrd<Timestamp> for Timestamp
impl PartialOrd<Timestamp> for Timestamp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more