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");
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_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

Performs the conversion.

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 returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

This method tests greater than or equal to (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"
);

The type returned in the event of a conversion error.

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.