pub struct Dtg { /* private fields */ }Expand description
Date time group
Implementations
sourceimpl Dtg
impl Dtg
sourcepub fn from(s: &str) -> Result<Self, DtgError>
pub fn from(s: &str) -> Result<Self, DtgError>
Create a Dtg from a string timestamp
use chrono::{TimeZone, Utc};
use dtg_lib::Dtg;
assert_eq!(
Dtg::from("1658448142").unwrap(),
Dtg::from_dt(&Utc.timestamp(1658448142, 0)),
);
assert_eq!(
Dtg::from("1658448142.936196858").unwrap(),
Dtg::from_dt(&Utc.timestamp(1658448142, 936196858)),
);sourcepub fn from_x(s: &str) -> Result<Self, DtgError>
pub fn from_x(s: &str) -> Result<Self, DtgError>
Create a Dtg from an “x” format timestamp
use chrono::{TimeZone, Utc};
use dtg_lib::Dtg;
assert_eq!(
Dtg::from_x("Xg6L02M").unwrap(),
Dtg::from_dt(&Utc.timestamp(1658448142, 0)),
);sourcepub fn rfc_3339(&self) -> String
pub fn rfc_3339(&self) -> String
Format as an RFC 3339 string
use dtg_lib::Dtg;
assert_eq!(
Dtg::from("1658448142").unwrap().rfc_3339(),
"2022-07-22T00:02:22Z",
);sourcepub fn format(&self, fmt: &Option<Format>, tz: &Option<Tz>) -> String
pub fn format(&self, fmt: &Option<Format>, tz: &Option<Tz>) -> String
Format as a string with format and timezone
use dtg_lib::{tz, Dtg, Format};
let dtg = Dtg::from("1658448142").unwrap();
assert_eq!(
dtg.format(&None, &None),
"2022-07-22T00:02:22Z",
);
assert_eq!(
dtg.format(&Some(Format::X), &None),
"Xg6L02M",
);
let a_fmt = Some(Format::Custom(String::from("%A")));
assert_eq!(
dtg.format(&a_fmt, &None),
"Friday",
);
assert_eq!(
dtg.format(&a_fmt, &tz("MST7MDT").ok()),
"Thursday",
);Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Dtg
impl Send for Dtg
impl Sync for Dtg
impl Unpin for Dtg
impl UnwindSafe for Dtg
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more