Skip to main content

DateTime

Struct DateTime 

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

A DateTime (or DateTimeImmutable): a timelib time with its zone.

== and < compare instants, as PHP’s do (timelib_time_compare): the same moment in two zones is equal.

Implementations§

Source§

impl DateTime

Source

pub fn new( time: &[u8], timezone: Option<&TimeZone>, default: &TzInfo, ) -> Result<DateTime, Error>

new DateTime($time, $timezone) at the current time.

Source

pub fn parse( time: &[u8], timezone: Option<&TimeZone>, default: &TzInfo, now: Timestamp, ) -> Result<DateTime, Error>

new DateTime($time, $timezone), with “now” (which fills what the string leaves out, and relative formats start from) given. default is the zone PHP takes from date.timezone.

Source

pub fn from_format( format: &[u8], time: &[u8], timezone: Option<&TimeZone>, default: &TzInfo, now: Timestamp, ) -> Result<Result<DateTime, Messages>, Error>

DateTime::createFromFormat($format, $time, $timezone) with “now” given.

Ok(Err(messages)) where PHP returns false (DateTime::getLastErrors() is Messages::to_php of them); Err where PHP throws (a NUL byte in time). Without ! or | in the format, fields the format does not set come from now.

Source

pub fn format(&self, format: &[u8]) -> Vec<u8> ⓘ

DateTime::format($format) (bytes: PHP copies format bytes verbatim).

Source

pub fn timestamp(&self) -> i64

DateTime::getTimestamp().

Source

pub fn microsecond(&self) -> i64

DateTime::getMicrosecond().

Source

pub fn offset(&self) -> i64

DateTime::getOffset().

Source

pub fn timezone(&self) -> Option<TimeZone>

DateTime::getTimezone() (None where PHP returns false).

Source

pub fn set_timezone(&mut self, timezone: &TimeZone)

DateTime::setTimezone($timezone).

Source

pub fn modify(&mut self, modifier: &[u8]) -> Result<(), Error>

DateTime::modify($modifier) (mutable DateTime).

Source

pub fn modified(&self, modifier: &[u8]) -> Result<DateTime, Error>

DateTimeImmutable::modify($modifier).

Source

pub fn modified_by(&self, modifier: &Modifier) -> DateTime

DateTimeImmutable::modify($modifier) with a Modifier parsed once.

Source

pub fn day_of_week(&self) -> i64

(int) $date->format('w'): the day of the week, 0 (Sunday) to 6.

Source

pub fn days_in_month(&self) -> i64

(int) $date->format('t'): the number of days in the month.

Source

pub fn set_date(&mut self, year: i64, month: i64, day: i64)

Sets the year, month and day, keeping the time of day and the zone.

Out-of-range values roll over (month 13 is January of the next year, day 0 the last day of the previous month) and the timestamp is recomputed. As in PHP, the fields are not re-derived from the new timestamp, so a wall time that falls in a DST gap still formats as set.

PHP: DateTime::setDate() / DateTimeImmutable::setDate().

Source

pub fn with_date(&self, year: i64, month: i64, day: i64) -> DateTime

DateTime::set_date on a copy.

PHP: DateTimeImmutable::setDate().

Source

pub fn set_time( &mut self, hour: i64, minute: i64, second: i64, microsecond: i64, )

Sets the hour, minute, second and microsecond, keeping the date and the zone.

Out-of-range values roll over into the next larger unit (hour 24 is midnight of the next day), and the fields are then re-derived from the new timestamp, so a wall time in a DST gap moves past it.

PHP: DateTime::setTime() / DateTimeImmutable::setTime() ($second and $microsecond default to 0 there).

Source

pub fn with_time( &self, hour: i64, minute: i64, second: i64, microsecond: i64, ) -> DateTime

DateTime::set_time on a copy.

PHP: DateTimeImmutable::setTime().

Source

pub fn add(&mut self, interval: &Interval)

DateTime::add($interval) for an interval made by DateInterval::createFromDateString().

Source

pub fn fields(&self) -> (i64, i64, i64, i64, i64, i64)

The broken-down fields (year, month, day, hour, minute, second).

Source§

impl DateTime

Source

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

timelib_time_compare (what <, > and == on DateTime use).

Trait Implementations§

Source§

impl Clone for DateTime

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 DateTime

Source§

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

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

impl PartialEq for DateTime

Source§

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

Whether both are the same instant, as PHP’s == on DateTime.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for DateTime

Source§

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

Orders by instant, as PHP’s < and > on DateTime.

1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
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.