pub struct FmtLocal2k { /* private fields */ }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.
impl FmtLocal2k
§Instantiation.
Source§impl FmtLocal2k
§Getters.
impl FmtLocal2k
§Getters.
Sourcepub const fn as_bytes(&self) -> &[u8] ⓘ
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.
);Sourcepub const fn date(&self) -> &str
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");Sourcepub const fn time(&self) -> &str
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.
impl FmtLocal2k
§Conversion.
Sourcepub fn to_rfc2822(&self) -> String
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),
);Sourcepub fn to_rfc3339(&self) -> String
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
impl AsRef<[u8]> for FmtLocal2k
Source§impl AsRef<str> for FmtLocal2k
impl AsRef<str> for FmtLocal2k
Source§impl Borrow<str> for FmtLocal2k
impl Borrow<str> for FmtLocal2k
Source§impl Clone for FmtLocal2k
impl Clone for FmtLocal2k
Source§fn clone(&self) -> FmtLocal2k
fn clone(&self) -> FmtLocal2k
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FmtLocal2k
impl Debug for FmtLocal2k
Source§impl Display for FmtLocal2k
impl Display for FmtLocal2k
Source§impl From<&FmtLocal2k> for Local2k
impl From<&FmtLocal2k> for Local2k
Source§fn from(src: &FmtLocal2k) -> Self
fn from(src: &FmtLocal2k) -> Self
Source§impl From<FmtLocal2k> for Local2k
impl From<FmtLocal2k> for Local2k
Source§fn from(src: FmtLocal2k) -> Self
fn from(src: FmtLocal2k) -> Self
Source§impl From<FmtLocal2k> for String
impl From<FmtLocal2k> for String
Source§fn from(src: FmtLocal2k) -> Self
fn from(src: FmtLocal2k) -> Self
Source§impl From<Local2k> for FmtLocal2k
impl From<Local2k> for FmtLocal2k
Source§impl Hash for FmtLocal2k
impl Hash for FmtLocal2k
Source§impl Ord for FmtLocal2k
impl Ord for FmtLocal2k
Source§impl PartialEq<&String> for FmtLocal2k
impl PartialEq<&String> for FmtLocal2k
Source§impl PartialEq<&str> for FmtLocal2k
impl PartialEq<&str> for FmtLocal2k
Source§impl PartialEq<FmtLocal2k> for &String
impl PartialEq<FmtLocal2k> for &String
Source§impl PartialEq<FmtLocal2k> for &str
impl PartialEq<FmtLocal2k> for &str
Source§impl PartialEq<FmtLocal2k> for String
impl PartialEq<FmtLocal2k> for String
Source§impl PartialEq<FmtLocal2k> for str
impl PartialEq<FmtLocal2k> for str
Source§impl PartialEq<String> for FmtLocal2k
impl PartialEq<String> for FmtLocal2k
Source§impl PartialEq<str> for FmtLocal2k
impl PartialEq<str> for FmtLocal2k
Source§impl PartialEq for FmtLocal2k
impl PartialEq for FmtLocal2k
Source§impl PartialOrd for FmtLocal2k
impl PartialOrd for FmtLocal2k
impl Copy for FmtLocal2k
impl Eq for FmtLocal2k
Auto Trait Implementations§
impl Freeze for FmtLocal2k
impl RefUnwindSafe for FmtLocal2k
impl Send for FmtLocal2k
impl Sync for FmtLocal2k
impl Unpin for FmtLocal2k
impl UnwindSafe for FmtLocal2k
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more