Struct DateTime

pub struct DateTime { /* private fields */ }

A civil time of a day on a particular Gregorian date.

Implementations

impl DateTime

const MIN: DateTime = _;

The minimum allowed Gregorian date and clock time.

const MAX: DateTime = _;

The maximum allowed Gregorian date and clock time.

const fn new(year: i16, month: i8, day: i8, hour: i8, minute: i8, second: i8, subsec_nanosecond: i32) -> Result<DateTime, RangeError>

Creates a new civil datetime from its constituent components.

If any of the values are out of their supported ranges, then an error is returned. Additionally, if year, month and day do not correspond to a valid Gregorian date, then an error is returned.

const fn from_parts(date: Date, time: Time) -> DateTime

Creates a new DateTime from its Date and Time components.

const fn date(&self) -> Date

Returns the Gregorian date component of this datetime.

const fn time(&self) -> Time

Returns the civil time component of this datetime.

const fn checked_add_seconds(&self, seconds: i32) -> Result<DateTime, RangeError>

Adds the given number of seconds to this civil datetime.

This returns an error when the resulting datetime would exceed either DateTime::MIN or DateTime::MAX.

const fn saturating_add_seconds(&self, seconds: i32) -> DateTime

Like DateTime::checked_add_seconds, but arithmetic saturates to either DateTime::MIN (when seconds < 0) or DateTime::MAX (when seconds > 0).

const fn to_timestamp(&self, offset: Offset) -> Result<Timestamp, RangeError>

Converts this datetime, along with its offset from UTC, to a corresponding Unix timestamp.

Note that unlike the reverse operation, Timestamp::to_datetime, this is fallible. This is by design. Namely, by making this routine fallible at the boundaries, it permits the reverse operation to be infallible. That is, all instants can be converted to a civil datetime (appropriate for formatting), but not all civil datetimes combined with all UTC offsets can be converted to an instant in time.

This errors when the timestamp returned would be outside the range given by Timestamp::MIN and Timestamp::MAX.

Trait Implementations

impl Clone for DateTime

fn clone(&self) -> DateTime

impl Copy for DateTime

impl Debug for DateTime

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

impl Eq for DateTime

impl Hash for DateTime

fn hash<__H: Hasher>(&self, state: &mut __H)

impl Ord for DateTime

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

impl PartialEq for DateTime

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

impl PartialOrd for DateTime

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

impl StructuralPartialEq for DateTime

Auto Trait Implementations

impl Freeze for DateTime

impl RefUnwindSafe for DateTime

impl Send for DateTime

impl Sync for DateTime

impl Unpin for DateTime

impl UnsafeUnpin for DateTime

impl UnwindSafe for DateTime

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for DateTime

fn from(t: T) -> T

Returns the argument unchanged.

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(self) -> U

Calls U::from(self).

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

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

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

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

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