pub struct Dtg { /* private fields */ }Expand description
Date time group
Implementations§
Source§impl Dtg
impl Dtg
Sourcepub fn from(s: &str) -> Result<Dtg, DtgError>
pub fn from(s: &str) -> Result<Dtg, DtgError>
Create a Dtg from a string timestamp
use dtg_lib::{Dtg, Timestamp};
assert_eq!(
Dtg::from("1658448142").unwrap(),
Dtg::from_dt(&Timestamp::new(1658448142, 0).unwrap()),
);
assert_eq!(
Dtg::from("1658448142.936196858").unwrap(),
Dtg::from_dt(&Timestamp::new(1658448142, 936196858).unwrap()),
);Sourcepub fn from_ymd_hms(
year: i16,
month: i8,
day: i8,
hour: i8,
minute: i8,
second: i8,
) -> Result<Dtg, DtgError>
pub fn from_ymd_hms( year: i16, month: i8, day: i8, hour: i8, minute: i8, second: i8, ) -> Result<Dtg, DtgError>
Create a Dtg from separate year, month, day, hour, minute, second values
use dtg_lib::{Dtg, Format};
let dtg = Dtg::from_ymd_hms(2022, 7, 22, 0, 2, 22).unwrap();
assert_eq!(dtg.format(&Some(Format::custom("%s")), &None), "1658448142");
assert_eq!(dtg.rfc_3339(), "2022-07-22T00:02:22Z");Sourcepub fn from_x(s: &str) -> Result<Dtg, DtgError>
pub fn from_x(s: &str) -> Result<Dtg, DtgError>
Create a Dtg from an “x” format timestamp
use dtg_lib::{Dtg, Format};
let dtg = Dtg::from_x("Xg6L02M").unwrap();
assert_eq!(dtg.format(&Some(Format::custom("%s")), &None), "1658448142");
assert_eq!(dtg.rfc_3339(), "2022-07-22T00:02:22Z");Sourcepub fn default(&self, tz: &Option<TimeZone>) -> String
pub fn default(&self, tz: &Option<TimeZone>) -> String
Format as a string
use dtg_lib::{tz, Dtg};
let dtg = Dtg::from("1658448142").unwrap();
let default_utc = "Fri 22 Jul 2022 00:02:22 UTC";
let default_mt = "Thu 21 Jul 2022 18:02:22 MDT";
assert_eq!(dtg.default(&None), default_utc);
assert_eq!(dtg.default(&tz("UTC").ok()), default_utc);
assert_eq!(dtg.default(&tz("MST7MDT").ok()), default_mt);Sourcepub fn rfc_3339(&self) -> String
pub fn rfc_3339(&self) -> String
Format as an RFC 3339 string
use dtg_lib::Dtg;
let dtg = Dtg::from("1658448142").unwrap();
assert_eq!(dtg.rfc_3339(), "2022-07-22T00:02:22Z");Sourcepub fn x_format(&self) -> String
pub fn x_format(&self) -> String
Format as “x” format
use dtg_lib::Dtg;
let dtg = Dtg::from("1658448142").unwrap();
assert_eq!(dtg.x_format(), "Xg6L02M");Sourcepub fn a_format(&self, tz: &Option<TimeZone>) -> String
pub fn a_format(&self, tz: &Option<TimeZone>) -> String
Format as “a” format
use dtg_lib::{tz, Dtg};
let dtg = Dtg::from("1658448142").unwrap();
let a_utc = "\
1658448142.000000000
2022-07-22T00:02:22Z
Fri 22 Jul 2022 00:02:22 UTC
Fri 22 Jul 2022 00:02:22 UTC";
let a_mt = "\
1658448142.000000000
2022-07-22T00:02:22Z
Fri 22 Jul 2022 00:02:22 UTC
Thu 21 Jul 2022 18:02:22 MDT";
assert_eq!(dtg.a_format(&None), a_utc);
// assert_eq!(dtg.a_format(&tz("UTC").ok()), a_utc);
// assert_eq!(dtg.a_format(&tz("MST7MDT").ok()), a_mt);Sourcepub fn bcd_format(&self) -> String
pub fn bcd_format(&self) -> String
Format like a binary clock using the Braille Patterns Unicode Block and | separators
use dtg_lib::Dtg;
let dtg = Dtg::from("1658448142").unwrap();
assert_eq!(dtg.bcd_format(), "⠄⠤|⢰|⠤|⠀|⠠|⠤"); // 2022|07|22|00|02|22Sourcepub fn format(&self, fmt: &Option<Format>, tz: &Option<TimeZone>) -> String
pub fn format(&self, fmt: &Option<Format>, tz: &Option<TimeZone>) -> 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("%A"));
assert_eq!(
dtg.format(&a_fmt, &None),
"Friday",
);
assert_eq!(
dtg.format(&a_fmt, &tz("MST7MDT").ok()),
"Thursday",
);pub fn elapsed(&self) -> Result<Duration, DtgError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Dtg
impl RefUnwindSafe for Dtg
impl Send for Dtg
impl Sync for Dtg
impl Unpin for Dtg
impl UnwindSafe for Dtg
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more