Struct utc2k::FmtUtc2k [−][src]
pub struct FmtUtc2k(_);
Expand description
Formatted UTC2K.
This is the formatted companion to Utc2k
. You can use it to obtain a
string version of the date, print it, etc.
While this acts essentially as a glorified String
, it is sized exactly
and therefore requires less memory to represent. It also implements Copy
.
It follows the simple Unix date format of YYYY-MM-DD HH:MM:SS
.
Speaking of, you can obtain an &str
using Deref
, AsRef<str>
,
Borrow<str>
, or FmtUtc2k::as_str
.
If you only want the date or time half, call FmtUtc2k::date
or
FmtUtc2k::time
respectively.
Examples
Generally it makes more sense to initialize a Utc2k
first, but you can
skip straight to a FmtUtc2k
instead:
use utc2k::{FmtUtc2k, Utc2k};
// Start with the current date/time.
let date = FmtUtc2k::now();
// Source from a specific timestamp.
let date = FmtUtc2k::from(946_684_800_u32);
assert_eq!(date.as_str(), "2000-01-01 00:00:00");
// Source from a `Utc2k`.
let utc_date = Utc2k::from(946_684_800_u32);
assert_eq!(FmtUtc2k::from(utc_date), utc_date.formatted());
Implementations
Minimum Value.
This is equivalent to 2000-01-01 00:00:00
.
Examples
use utc2k::FmtUtc2k;
let date = FmtUtc2k::min();
assert_eq!(date.as_str(), "2000-01-01 00:00:00");
Maximum Value.
This is equivalent to 2099-12-31 23:59:59
.
Examples
use utc2k::FmtUtc2k;
let date = FmtUtc2k::max();
assert_eq!(date.as_str(), "2099-12-31 23:59:59");
Set Date/Time.
This can be used to recycle an existing buffer.
As with all other part-based operations, overflows and underflows will
be adjusted automatically, with minimum and maximum dates capped to
FmtUtc2k::min
and FmtUtc2k::max
respectively.
Examples
use utc2k::{FmtUtc2k, Utc2k};
let mut fmt = FmtUtc2k::default();
assert_eq!(fmt.as_str(), "2000-01-01 00:00:00");
fmt.set_datetime(Utc2k::from(Utc2k::MAX_UNIXTIME));
assert_eq!(fmt.as_str(), "2099-12-31 23:59:59");
Set Parts.
This can be used to recycle an existing buffer.
As with all other part-based operations, overflows and underflows will
be adjusted automatically, with minimum and maximum dates capped to
FmtUtc2k::min
and FmtUtc2k::max
respectively.
Examples
use utc2k::{FmtUtc2k, Utc2k};
let mut fmt = FmtUtc2k::default();
assert_eq!(fmt.as_str(), "2000-01-01 00:00:00");
fmt.set_parts(2010, 10, 31, 12, 33, 59);
assert_eq!(fmt.as_str(), "2010-10-31 12:33:59");
// And if you do something weird with the dates...
fmt.set_parts(2010, 10, 32, 12, 33, 59);
assert_eq!(fmt.as_str(), "2010-11-01 12:33:59");
Set Unixtime.
This can be used to recycle an existing buffer.
As with all other part-based operations, overflows and underflows will
be adjusted automatically, with minimum and maximum dates capped to
Utc2k::MIN_UNIXTIME
and Utc2k::MAX_UNIXTIME
respectively.
Examples
use utc2k::{FmtUtc2k, Utc2k};
let mut fmt = FmtUtc2k::from(Utc2k::MIN_UNIXTIME);
assert_eq!(fmt.as_str(), "2000-01-01 00:00:00");
fmt.set_unixtime(Utc2k::MAX_UNIXTIME);
assert_eq!(fmt.as_str(), "2099-12-31 23:59:59");
As Bytes.
Return a byte string slice in YYYY-MM-DD HH:MM:SS
format.
A byte slice can also be obtained using FmtUtc2k::as_ref
.
Examples
use utc2k::FmtUtc2k;
let fmt = FmtUtc2k::max();
assert_eq!(fmt.as_bytes(), b"2099-12-31 23:59:59");
As Str.
Return a string slice in YYYY-MM-DD HH:MM:SS
format.
A string slice can also be obtained using FmtUtc2k::as_ref
or
through dereferencing.
Examples
use utc2k::FmtUtc2k;
let fmt = FmtUtc2k::max();
assert_eq!(fmt.as_str(), "2099-12-31 23:59:59");
Just the Date Bits.
This returns the date as a string slice in YYYY-MM-DD
format.
Examples
use utc2k::{FmtUtc2k, Utc2k};
let fmt = FmtUtc2k::from(Utc2k::MAX_UNIXTIME);
assert_eq!(fmt.as_str(), "2099-12-31 23:59:59");
assert_eq!(fmt.date(), "2099-12-31");
Just the Time Bits.
This returns the time as a string slice in HH:MM:SS
format.
Examples
use utc2k::{FmtUtc2k, Utc2k};
let fmt = FmtUtc2k::from(Utc2k::MAX_UNIXTIME);
assert_eq!(fmt.as_str(), "2099-12-31 23:59:59");
assert_eq!(fmt.time(), "23:59:59");
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
From OsStr
.
use std::ffi::OsStr;
use utc2k::FmtUtc2k;
assert_eq!(
FmtUtc2k::try_from(OsStr::new("2013-12-15 21:30:02")).unwrap().as_str(),
"2013-12-15 21:30:02"
);
assert_eq!(
FmtUtc2k::try_from(OsStr::new("2013-12-15")).unwrap().as_str(),
"2013-12-15 00:00:00"
);
type Error = Utc2kError
type Error = Utc2kError
The type returned in the event of a conversion error.
Auto Trait Implementations
impl RefUnwindSafe for FmtUtc2k
impl UnwindSafe for FmtUtc2k
Blanket Implementations
Mutably borrows from an owned value. Read more