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

Now.

This returns an instance using the current unixtime as the seed.

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

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.