Skip to main content

PhpDateTime

Struct PhpDateTime 

Source
pub struct PhpDateTime { /* private fields */ }
Expand description

A date and time with its time zone: what DateTime::format() prints and createFromFormat() returns.

Build one from a jiff civil::DateTime (read as UTC), a Timestamp (UTC), a ZonedDateTime, or with PhpDateTime::new.

It covers every wall-clock time jiff’s civil::DateTime does (years -9999 to 9999), which is a little more than its Timestamp: at both ends timestamp still answers, and to_timestamp is an error.

Implementations§

Source§

impl PhpDateTime

Source

pub fn new(local: DateTime, zone: Zone) -> Result<Self, Error>

A wall-clock time in zone. A time that does not exist there (the hour a daylight saving change skips) moves forward, as PHP moves it, and a time that happens twice is the first one (Disambiguation::Compatible).

PHP does not always take the first one: for new DateTime($time, $zone) and for a createFromFormat() value that names no zone, it takes the second when the clocks go back to UTC+0 or ahead of it, as in Europe/London, Europe/Madrid or Australia/Sydney. Use new_with to choose.

§Errors

For an offset out of range, or when a skipped hour moves past the last date jiff supports.

Source

pub fn new_with( local: DateTime, zone: Zone, disambiguation: Disambiguation, ) -> Result<Self, Error>

new, choosing what happens with a wall-clock time that a Zone::Named skips or repeats. The other zones have a single offset, so disambiguation changes nothing for them.

§Errors

Those of new, and Disambiguation::Reject for a skipped or repeated time.

Source

pub fn from_utc(utc: DateTime, zone: Zone) -> Result<Self, Error>

The instant utc (a UTC wall-clock time) seen from zone.

§Errors

For an offset out of range, or a result outside the dates jiff supports.

Source

pub fn from_timestamp(timestamp: Timestamp, zone: Zone) -> Result<Self, Error>

The instant timestamp seen from zone.

§Errors

For an offset out of range.

Source

pub fn in_zone(&self, zone: Zone) -> Result<Self, Error>

The same instant in another zone.

§Errors

For an offset out of range, or a result outside the dates jiff supports.

Source

pub const fn datetime(&self) -> &DateTime

The wall-clock time, without the zone.

Source

pub const fn zone(&self) -> &Zone

The zone.

Source

pub const fn offset_seconds(&self) -> i32

Seconds east of UTC at this instant (Z).

Source

pub const fn is_dst(&self) -> bool

Whether daylight saving time is in effect (I).

Source

pub fn abbreviation(&self) -> &str

The zone abbreviation at this instant, as T prints it.

Source

pub fn to_timestamp(&self) -> Result<Timestamp, Error>

The instant.

§Errors

When the instant falls outside the range of jiff’s Timestamp.

Source

pub fn timestamp(&self) -> i64

The Unix timestamp (U): whole seconds, rounded down as PHP does, so half a second before 1970 is -1.

Source

pub fn to_zoned_datetime(&self) -> Result<ZonedDateTime, Error>

The instant as a jiff ZonedDateTime.

§Errors

When the instant falls outside the range of jiff’s Timestamp.

Trait Implementations§

Source§

impl Clone for PhpDateTime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PhpDateTime

Source§

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

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

impl Eq for PhpDateTime

Source§

impl From<&DateTime> for PhpDateTime

Source§

fn from(local: &DateTime) -> Self

Read as UTC.

Source§

impl From<&PhpDateTime> for PhpDateTime

Source§

fn from(date: &Self) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime> for PhpDateTime

Source§

fn from(local: DateTime) -> Self

Read as UTC.

Source§

impl From<Timestamp> for PhpDateTime

Source§

fn from(timestamp: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<ZonedDateTime> for PhpDateTime

Source§

fn from(date: ZonedDateTime) -> Self

The wall-clock time, offset and zone of date.

Source§

impl PartialEq for PhpDateTime

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PhpDateTime

Auto Trait Implementations§

§

impl Forget for PhpDateTime

§

impl Freeze for PhpDateTime

§

impl Move for PhpDateTime

§

impl RefUnwindSafe for PhpDateTime

§

impl Send for PhpDateTime
where RawVecInner: Send, Repr: Send, &'static str: Send, String: Send,

§

impl Sync for PhpDateTime
where RawVecInner: Sync, Repr: Sync, String: Sync,

§

impl Unpin for PhpDateTime
where *const u8 is !null: Unpin, *const u8: Unpin, &'static str: Unpin, String: Unpin,

§

impl UnsafeUnpin for PhpDateTime

§

impl UnwindSafe for PhpDateTime
where RawVecInner: UnwindSafe, *const u8: UnwindSafe, &'static str: UnwindSafe, String: UnwindSafe,

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.