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
impl DateTime
Sourcepub fn new(
time: &[u8],
timezone: Option<&TimeZone>,
default: &TzInfo,
) -> Result<DateTime, Error>
pub fn new( time: &[u8], timezone: Option<&TimeZone>, default: &TzInfo, ) -> Result<DateTime, Error>
new DateTime($time, $timezone) at the current time.
Sourcepub fn parse(
time: &[u8],
timezone: Option<&TimeZone>,
default: &TzInfo,
now: Timestamp,
) -> Result<DateTime, Error>
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.
Sourcepub fn from_format(
format: &[u8],
time: &[u8],
timezone: Option<&TimeZone>,
default: &TzInfo,
now: Timestamp,
) -> Result<Result<DateTime, Messages>, Error>
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.
Sourcepub fn format(&self, format: &[u8]) -> Vec<u8> ⓘ
pub fn format(&self, format: &[u8]) -> Vec<u8> ⓘ
DateTime::format($format) (bytes: PHP copies format bytes verbatim).
Sourcepub fn microsecond(&self) -> i64
pub fn microsecond(&self) -> i64
DateTime::getMicrosecond().
Sourcepub fn timezone(&self) -> Option<TimeZone>
pub fn timezone(&self) -> Option<TimeZone>
DateTime::getTimezone() (None where PHP returns false).
Sourcepub fn set_timezone(&mut self, timezone: &TimeZone)
pub fn set_timezone(&mut self, timezone: &TimeZone)
DateTime::setTimezone($timezone).
Sourcepub fn modify(&mut self, modifier: &[u8]) -> Result<(), Error>
pub fn modify(&mut self, modifier: &[u8]) -> Result<(), Error>
DateTime::modify($modifier) (mutable DateTime).
Sourcepub fn modified(&self, modifier: &[u8]) -> Result<DateTime, Error>
pub fn modified(&self, modifier: &[u8]) -> Result<DateTime, Error>
DateTimeImmutable::modify($modifier).
Sourcepub fn modified_by(&self, modifier: &Modifier) -> DateTime
pub fn modified_by(&self, modifier: &Modifier) -> DateTime
DateTimeImmutable::modify($modifier) with a Modifier parsed once.
Sourcepub fn day_of_week(&self) -> i64
pub fn day_of_week(&self) -> i64
(int) $date->format('w'): the day of the week, 0 (Sunday) to 6.
Sourcepub fn days_in_month(&self) -> i64
pub fn days_in_month(&self) -> i64
(int) $date->format('t'): the number of days in the month.
Sourcepub fn set_date(&mut self, year: i64, month: i64, day: i64)
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().
Sourcepub fn with_date(&self, year: i64, month: i64, day: i64) -> DateTime
pub fn with_date(&self, year: i64, month: i64, day: i64) -> DateTime
DateTime::set_date on a copy.
PHP: DateTimeImmutable::setDate().
Sourcepub fn set_time(
&mut self,
hour: i64,
minute: i64,
second: i64,
microsecond: i64,
)
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).
Sourcepub fn with_time(
&self,
hour: i64,
minute: i64,
second: i64,
microsecond: i64,
) -> DateTime
pub fn with_time( &self, hour: i64, minute: i64, second: i64, microsecond: i64, ) -> DateTime
DateTime::set_time on a copy.
PHP: DateTimeImmutable::setTime().
Trait Implementations§
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Orders by instant, as PHP’s < and > on DateTime.