pub struct DateTime { /* private fields */ }Expand description
A DateTime object.
This has minimal introspection methods. It is not an attempt to build a complete DateTime API.
Prefer to use its implementation of chrono::Datelike and chrono::Timelike or simply the
DateTime::to_chrono method to use a specific chrono::TimeZone, all available with features = ["chrono"].
Also, its Display implementation is geared towards lossless EDTF parse-format roundtrips. It
does not always produce valid RFC3339 timestamps, in particular TzOffset::Hours is rendered
as +04 instead of +04:00. This is best considered a problem with the EDTF specification for
allowing a useless extra timestamp format.
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub fn date(&self) -> DateComplete
pub fn date(&self) -> DateComplete
Gets the date portion
Sourcepub fn offset(&self) -> TzOffset
pub fn offset(&self) -> TzOffset
Get the TzOffset. If None is returned, this represents a timestamp which did not
specify a timezone.
If using the chrono interop, None means you should attempt to convert to a chrono::NaiveDate
Sourcepub fn to_chrono_naive(&self) -> NaiveDateTime
Available on crate feature chrono only.
pub fn to_chrono_naive(&self) -> NaiveDateTime
chrono only.Convert to a chrono::NaiveDate
Sourcepub fn to_chrono<Tz>(&self, tz: &Tz) -> DateTime<Tz>where
Tz: TimeZone,
Available on crate feature chrono only.
pub fn to_chrono<Tz>(&self, tz: &Tz) -> DateTime<Tz>where
Tz: TimeZone,
chrono only.use edtf::level_1::Edtf;
use chrono::TimeZone;
let utc = chrono::Utc;
assert_eq!(
Edtf::parse("2004-02-29T01:47:00+05:00")
.unwrap()
.as_datetime()
.unwrap()
.to_chrono(&utc),
utc.ymd(2004, 02, 28).and_hms(20, 47, 00)
);Trait Implementations§
Source§impl Datelike for DateTime
Available on crate feature chrono only.Convenience chrono::Datelike implementation, which mostly relies on internal conversion to
chrono::NaiveDate.
impl Datelike for DateTime
chrono only.Convenience chrono::Datelike implementation, which mostly relies on internal conversion to chrono::NaiveDate.
Source§fn year(&self) -> i32
fn year(&self) -> i32
Source§fn with_year(&self, year: i32) -> Option<Self>
fn with_year(&self, year: i32) -> Option<Self>
Source§fn with_month(&self, month: u32) -> Option<Self>
fn with_month(&self, month: u32) -> Option<Self>
Source§fn with_month0(&self, month0: u32) -> Option<Self>
fn with_month0(&self, month0: u32) -> Option<Self>
Source§fn with_day(&self, day: u32) -> Option<Self>
fn with_day(&self, day: u32) -> Option<Self>
Source§fn with_day0(&self, day0: u32) -> Option<Self>
fn with_day0(&self, day0: u32) -> Option<Self>
Source§fn with_ordinal(&self, ordinal: u32) -> Option<Self>
fn with_ordinal(&self, ordinal: u32) -> Option<Self>
Source§fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>
fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>
Source§fn year_ce(&self) -> (bool, u32)
fn year_ce(&self) -> (bool, u32)
Source§fn num_days_from_ce(&self) -> i32
fn num_days_from_ce(&self) -> i32
Source§fn num_days_in_month(&self) -> u8
fn num_days_in_month(&self) -> u8
Source§impl Timelike for DateTime
Available on crate feature chrono only.
impl Timelike for DateTime
chrono only.