FmtLocal2k

Struct FmtLocal2k 

Source
pub struct FmtLocal2k { /* private fields */ }
Available on crate feature local only.
Expand description

§Formatted Local UTC2K.

This is the formatted companion to Local2k. 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 AsRef<str>, Borrow<str>, or FmtLocal2k::as_str.

If you only want the date or time half, call FmtLocal2k::date or FmtLocal2k::time respectively.

See Local2k for limitations and gotchas.

Implementations§

Source§

impl FmtLocal2k

§Instantiation.
Source

pub fn now() -> Self

§Now.

Create a new instance representing the current local time.

use utc2k::{FmtLocal2k, Local2k};

// Equivalent.
assert_eq!(
    FmtLocal2k::now(),
    FmtLocal2k::from(Local2k::now()),
);
Source§

impl FmtLocal2k

§Getters.
Source

pub const fn as_bytes(&self) -> &[u8]

§As Bytes.

Return a byte string slice in YYYY-MM-DD hh:mm:ss format.

A byte slice can also be obtained using FmtLocal2k::as_ref.

§Examples
use utc2k::{Local2k, Utc2k};

let fmt = Local2k::from(Utc2k::MAX).formatted();
assert_eq!(
    fmt.as_bytes(),
    b"2099-12-31 15:59:59", // e.g. California.
);
Source

pub const fn as_str(&self) -> &str

§As Str.

Return a string slice in YYYY-MM-DD hh:mm:ss format.

§Examples
use utc2k::{Local2k, Utc2k};

let fmt = Local2k::from(Utc2k::MAX).formatted();
assert_eq!(
    fmt.as_str(),
    "2099-12-31 15:59:59", // e.g. California.
);
Source

pub const fn date(&self) -> &str

§Just the Date Bits.

This returns the date as a string slice in YYYY-MM-DD format.

§Examples
use utc2k::{Local2k, Utc2k};

let utc = Utc2k::new(2025, 6, 19, 18, 57, 12);
let fmt = Local2k::from(utc).formatted();
assert_eq!(
    fmt.as_str(),
    "2025-06-19 11:57:12", // e.g. California.
);
assert_eq!(fmt.date(), "2025-06-19");
Source

pub const fn year(&self) -> &str

§Just the Year Bit.

This returns the year as a string slice.

§Examples
use utc2k::{Local2k, Utc2k};

let utc = Utc2k::new(2025, 6, 19, 18, 57, 12);
let fmt = Local2k::from(utc).formatted();
assert_eq!(
    fmt.as_str(),
    "2025-06-19 11:57:12", // e.g. California.
);
assert_eq!(fmt.year(), "2025");
Source

pub const fn time(&self) -> &str

§Just the Time Bits.

This returns the time as a string slice in hh:mm:ss format.

§Examples
use utc2k::{Local2k, Utc2k};

let utc = Utc2k::new(2025, 6, 19, 18, 57, 12);
let fmt = Local2k::from(utc).formatted();
assert_eq!(
    fmt.as_str(),
    "2025-06-19 11:57:12", // e.g. California.
);
assert_eq!(fmt.time(), "11:57:12");
Source§

impl FmtLocal2k

§Conversion.
Source

pub fn to_rfc2822(&self) -> String

§To RFC2822.

Return a string formatted according to RFC2822.

§Examples
use utc2k::{Local2k, Utc2k};

// A proper UTC date in RFC2822.
let utc = Utc2k::new(2021, 12, 13, 04, 56, 1);
assert_eq!(
    utc.to_rfc2822(),
    "Mon, 13 Dec 2021 04:56:01 +0000",
);

// The same date localized to, say, California.
let local = Local2k::from(utc).formatted();
assert_eq!(
    local.to_rfc2822(),
    "Sun, 12 Dec 2021 20:56:01 -0800",
);

The RFC2822 date/time format is portable, whether local or UTC.

let utc_2822 = utc.to_rfc2822();
let local_2822 = local.to_rfc2822();

// The RFC2822 representations will vary if there's an offset, but
// if parsed back into a Utc2k, that'll get sorted and they'll match!
assert_eq!(
    Utc2k::from_rfc2822(utc_2822.as_bytes()),
    Some(utc),
);
assert_eq!(
    Utc2k::from_rfc2822(local_2822.as_bytes()),
    Some(utc),
);
Source

pub fn to_rfc3339(&self) -> String

§To RFC3339.

Return a string formatted according to RFC3339.

§Examples
use utc2k::{Local2k, Utc2k};

// A proper UTC date in RFC3339.
let utc = Utc2k::new(2021, 12, 13, 11, 56, 1);
assert_eq!(utc.to_rfc3339(), "2021-12-13T11:56:01Z");

// The same date localized to, say, California.
let local = Local2k::from(utc).formatted();
assert_eq!(local.to_rfc3339(), "2021-12-13T03:56:01-0800");

The RFC3339 date/time format is portable, whether local or UTC.

let utc_3339 = utc.to_rfc3339();
let local_3339 = local.to_rfc3339();

// The RFC3339 representations will vary if there's an offset, but
// if parsed back into a Utc2k, that'll get sorted and they'll match!
assert_eq!(
    Utc2k::from_ascii(utc_3339.as_bytes()),
    Some(utc),
);
assert_eq!(
    Utc2k::from_ascii(local_3339.as_bytes()),
    Some(utc),
);

Trait Implementations§

Source§

impl AsRef<[u8]> for FmtLocal2k

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for FmtLocal2k

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<str> for FmtLocal2k

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl Clone for FmtLocal2k

Source§

fn clone(&self) -> FmtLocal2k

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FmtLocal2k

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for FmtLocal2k

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&FmtLocal2k> for Local2k

Source§

fn from(src: &FmtLocal2k) -> Self

Converts to this type from the input type.
Source§

impl From<FmtLocal2k> for Local2k

Source§

fn from(src: FmtLocal2k) -> Self

Converts to this type from the input type.
Source§

impl From<FmtLocal2k> for String

Source§

fn from(src: FmtLocal2k) -> Self

Converts to this type from the input type.
Source§

impl From<Local2k> for FmtLocal2k

Source§

fn from(src: Local2k) -> Self

Converts to this type from the input type.
Source§

impl Hash for FmtLocal2k

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for FmtLocal2k

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<&Box<str>> for FmtLocal2k

Source§

fn eq(&self, other: &&Box<str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&Cow<'_, str>> for FmtLocal2k

Source§

fn eq(&self, other: &&Cow<'_, str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&String> for FmtLocal2k

Source§

fn eq(&self, other: &&String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for FmtLocal2k

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Box<str>> for FmtLocal2k

Source§

fn eq(&self, other: &Box<str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Cow<'_, str>> for FmtLocal2k

Source§

fn eq(&self, other: &Cow<'_, str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for &Box<str>

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for &Cow<'_, str>

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for &String

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for &str

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for Box<str>

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for Cow<'_, str>

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for String

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<FmtLocal2k> for str

Source§

fn eq(&self, other: &FmtLocal2k) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for FmtLocal2k

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for FmtLocal2k

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for FmtLocal2k

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for FmtLocal2k

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for FmtLocal2k

Source§

impl Eq for FmtLocal2k

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.