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
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_timestamp(Utc2k::MAX_UNIXTIME); 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
Auto Trait Implementations
impl RefUnwindSafe for FmtUtc2k
impl UnwindSafe for FmtUtc2k
Blanket Implementations
Mutably borrows from an owned value. Read more