pub struct Utc2k { /* private fields */ }
Expand description
§UTC2K.
This is a lightweight date/time object for UTC date ranges within the
current century (e.g. 2000-01-01 00:00:00
to 2099-12-31 23:59:59
).
Values outside this range are saturated to fit, unless using
Utc2k::checked_from_unixtime
.
To instantiate from a UTC unix timestamp, use From<u32>
. To try to parse
from a YYYY-MM-DD HH:MM:SS
string, use TryFrom<&str>
or FromStr
.
To manually construct from individual parts, you can just call Utc2k::new
.
A Utc2k
object can be turned back into its constituent parts via
Utc2k::parts
, or the individual methods like Utc2k::year
, Utc2k::month
,
etc.
It can be converted into a unix timestamp with Utc2k::unixtime
.
§Examples
use utc2k::Utc2k;
let date = Utc2k::default(); // 2000-01-01 00:00:00
let date = Utc2k::now(); // The current time.
let date = Utc2k::from(4_102_444_799_u32); // 2099-12-31 23:59:59
// String parsing is fallible, but flexible. So long as the numbers we
// need are in the right place, it will be fine.
assert!(Utc2k::try_from("2099-12-31 23:59:59").is_ok()); // Fine.
assert!(Utc2k::try_from("2099-12-31T23:59:59.0000").is_ok()); // Also fine.
assert!(Utc2k::try_from("2099-12-31").is_ok()); // Also fine, but midnight.
assert!(Utc2k::try_from("January 1, 2010").is_err()); // Nope!
Implementations§
source§impl Utc2k
impl Utc2k
§Min/Max.
sourcepub const MIN_UNIXTIME: u32 = 946_684_800u32
pub const MIN_UNIXTIME: u32 = 946_684_800u32
§Minimum Timestamp.
sourcepub const MAX_UNIXTIME: u32 = 4_102_444_799u32
pub const MAX_UNIXTIME: u32 = 4_102_444_799u32
§Maximum Timestamp.
source§impl Utc2k
impl Utc2k
§Instantiation.
sourcepub fn new(y: u16, m: u8, d: u8, hh: u8, mm: u8, ss: u8) -> Self
pub fn new(y: u16, m: u8, d: u8, hh: u8, mm: u8, ss: u8) -> Self
§New (From Parts).
This will create a new instance from individual year, month, etc., parts.
Overflowing units will be carried over where appropriate, so for example, 13 months becomes 1 year and 1 month.
Dates prior to 2000 or after 2099 will be saturated to fit.
§Examples
use utc2k::Utc2k;
let date = Utc2k::new(2010, 5, 5, 16, 30, 1);
assert_eq!(date.to_string(), "2010-05-05 16:30:01");
sourcepub fn now_local() -> Self
Available on crate feature local
only.
pub fn now_local() -> Self
local
only.§Now (Local).
This returns an instance using the current, local time as the seed. If
no local offset can be determined, this is equivalent to Utc2k::now
.
Refer to LocalOffset
for important caveats and
limitations.
source§impl Utc2k
impl Utc2k
§String Parsing.
sourcepub fn from_datetime_str<B>(src: B) -> Result<Self, Utc2kError>
pub fn from_datetime_str<B>(src: B) -> Result<Self, Utc2kError>
§From Date/Time.
Parse a string containing a date/time in YYYY-MM-DD HH:MM:SS
format.
This operation is naive and only looks at the positions where numbers
are expected.
In other words, 2020-01-01 00:00:00
will parse the same as
2020/01/01 00:00:00
or even 2020-01-01 00:00:00.0000 PDT
.
As with all the other methods, dates outside the 2000..=2099
range
will be saturated (non-failing), and overflows will be carried over to
the appropriate unit (e.g. 13 months will become +1 year and 1 month).
§Examples
use utc2k::Utc2k;
// This isn't long enough.
assert!(Utc2k::from_datetime_str("2021/06/25").is_err());
// This is fine.
let date = Utc2k::from_datetime_str("2021-06-25 13:15:25.0000").unwrap();
assert_eq!(date.to_string(), "2021-06-25 13:15:25");
// This is all wrong.
assert!(Utc2k::from_datetime_str("Applebutter").is_err());
§Errors
If any of the digits fail to parse, or if the string is insufficiently sized, an error will be returned.
sourcepub fn from_smooshed_datetime_str<B>(src: B) -> Result<Self, Utc2kError>
pub fn from_smooshed_datetime_str<B>(src: B) -> Result<Self, Utc2kError>
§From Date/Time (Smooshed).
This is just like Utc2k::from_datetime_str
for “smooshed” datetime
strings, i.e. YYYYMMDDHHMMSS
(no separators).
§Examples
use utc2k::Utc2k;
// This isn't long enough.
assert!(Utc2k::from_smooshed_datetime_str("20210625").is_err());
// This is fine.
let date = Utc2k::from_smooshed_datetime_str("20210625131525").unwrap();
assert_eq!(date.to_string(), "2021-06-25 13:15:25");
// This *won't* work because there are separators in the way.
assert!(Utc2k::from_smooshed_datetime_str("2021-06-25 13:15:25").is_err());
// This is all wrong.
assert!(Utc2k::from_smooshed_datetime_str("Applebutterful").is_err());
§Errors
If any of the digits fail to parse, or if the string is insufficiently sized, an error will be returned.
sourcepub fn from_date_str<B>(src: B) -> Result<Self, Utc2kError>
pub fn from_date_str<B>(src: B) -> Result<Self, Utc2kError>
§From Date.
Parse a string containing a date/time in YYYY-MM-DD
format. This
operation is naive and only looks at the positions where numbers are
expected.
In other words, 2020-01-01
will parse the same as 2020/01/01
or
even 2020-01-01 13:03:33.5900 PDT
.
As with all the other methods, dates outside the 2000..=2099
range
will be saturated (non-failing), and overflows will be carried over to
the appropriate unit (e.g. 13 months will become +1 year and 1 month).
The time will always be set to midnight when using this method.
§Examples
use utc2k::Utc2k;
// This is fine.
let date = Utc2k::from_date_str("2021/06/25").unwrap();
assert_eq!(date.to_string(), "2021-06-25 00:00:00");
// This is fine, but the time will be ignored.
let date = Utc2k::from_date_str("2021-06-25 13:15:25.0000").unwrap();
assert_eq!(date.to_string(), "2021-06-25 00:00:00");
// This is all wrong.
assert!(Utc2k::from_date_str("Applebutter").is_err());
§Errors
If any of the digits fail to parse, or if the string is insufficiently sized, an error will be returned.
sourcepub fn from_smooshed_date_str<B>(src: B) -> Result<Self, Utc2kError>
pub fn from_smooshed_date_str<B>(src: B) -> Result<Self, Utc2kError>
§From Date (Smooshed).
This is just like Utc2k::from_date_str
for “smooshed” date strings,
i.e. YYYYMMDD
(no separators).
§Examples
use utc2k::Utc2k;
// This is fine.
let date = Utc2k::from_smooshed_date_str("20210625").unwrap();
assert_eq!(date.to_string(), "2021-06-25 00:00:00");
// This is fine, but the time will be ignored.
let date = Utc2k::from_smooshed_date_str("20210625131525").unwrap();
assert_eq!(date.to_string(), "2021-06-25 00:00:00");
// This *won't* work because it has dashes in the way.
assert!(Utc2k::from_smooshed_date_str("2021-06-25").is_err());
// This is all wrong.
assert!(Utc2k::from_smooshed_date_str("Applebutter").is_err());
§Errors
If any of the digits fail to parse, or if the string is insufficiently sized, an error will be returned.
sourcepub fn parse_time_str<B>(src: B) -> Result<(u8, u8, u8), Utc2kError>
pub fn parse_time_str<B>(src: B) -> Result<(u8, u8, u8), Utc2kError>
§Parse Time.
This method attempts to parse a time string in the HH:MM:SS
format,
returning the hours, minutes, and seconds as integers.
As with other methods in this library, only positions where numbers are
expected will be looked at. 01:02:03
will parse the same way as
01-02-03
.
§Examples
use utc2k::Utc2k;
assert_eq!(
Utc2k::parse_time_str("15:35:47"),
Ok((15, 35, 47))
);
// The hours are out of range.
assert!(Utc2k::parse_time_str("30:35:47").is_err());
§Errors
This method will return an error if any of the numeric bits are invalid or out of range (hours must be < 24, minutes and seconds < 60).
source§impl Utc2k
impl Utc2k
§Get Parts.
sourcepub const fn parts(self) -> (u16, u8, u8, u8, u8, u8)
pub const fn parts(self) -> (u16, u8, u8, u8, u8, u8)
§Parts.
Return the year, month, etc., parts.
Alternatively, if you only want the date bits, use Utc2k::ymd
, or
if you only want the time bits, use Utc2k::hms
.
§Examples
use utc2k::Utc2k;
let date = Utc2k::new(2010, 5, 4, 16, 30, 1);
assert_eq!(date.parts(), (2010, 5, 4, 16, 30, 1));
sourcepub const fn ymd(self) -> (u16, u8, u8)
pub const fn ymd(self) -> (u16, u8, u8)
§Date Parts.
Return the year, month, and day.
If you want the time too, call Utc2k::parts
instead.
§Examples
use utc2k::Utc2k;
let date = Utc2k::new(2010, 5, 5, 16, 30, 1);
assert_eq!(date.ymd(), (2010, 5, 5));
sourcepub const fn hms(self) -> (u8, u8, u8)
pub const fn hms(self) -> (u8, u8, u8)
§Time Parts.
Return the hours, minutes, and seconds.
If you want the date too, call Utc2k::parts
instead.
§Examples
use utc2k::Utc2k;
let date = Utc2k::new(2010, 5, 5, 16, 30, 1);
assert_eq!(date.hms(), (16, 30, 1));
sourcepub const fn month_enum(self) -> Month
pub const fn month_enum(self) -> Month
source§impl Utc2k
impl Utc2k
§Other Getters.
sourcepub const fn month_abbreviation(self) -> &'static str
pub const fn month_abbreviation(self) -> &'static str
sourcepub const fn month_name(self) -> &'static str
pub const fn month_name(self) -> &'static str
sourcepub const fn month_size(self) -> u8
pub const fn month_size(self) -> u8
§Month Size (Days).
This returns the total number of days this month could hold, or put another way, the last day of this month.
The value will always be between 28..=31
, with leap Februaries
returning 29
.
§Examples
use utc2k::Utc2k;
let date = Utc2k::try_from("2021-07-08 13:22:01").unwrap();
assert_eq!(date.month_size(), 31);
sourcepub const fn ordinal(self) -> u16
pub const fn ordinal(self) -> u16
§Ordinal.
Return the day-of-year value. This will be between 1..=365
(or 1..=366
for leap years).
§Examples
use utc2k::Utc2k;
let date = Utc2k::try_from("2020-05-10 00:00:00").unwrap();
assert_eq!(date.ordinal(), 131);
let date = Utc2k::try_from("2021-01-15 00:00:00").unwrap();
assert_eq!(date.ordinal(), 15);
sourcepub const fn seconds_from_midnight(self) -> u32
pub const fn seconds_from_midnight(self) -> u32
§Seconds From Midnight.
Return the number of seconds since midnight. In other words, this adds up all of the time bits.
§Examples
use utc2k::Utc2k;
let date = Utc2k::new(2010, 11, 30, 0, 0, 0);
assert_eq!(date.seconds_from_midnight(), 0);
let date = Utc2k::new(2010, 11, 30, 0, 0, 30);
assert_eq!(date.seconds_from_midnight(), 30);
let date = Utc2k::new(2010, 11, 30, 0, 1, 30);
assert_eq!(date.seconds_from_midnight(), 90);
let date = Utc2k::new(2010, 11, 30, 12, 30, 10);
assert_eq!(date.seconds_from_midnight(), 45_010);
source§impl Utc2k
impl Utc2k
§Conversion.
sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
sourcepub fn to_rfc2822(&self) -> String
pub fn to_rfc2822(&self) -> String
§To RFC2822.
Return a string formatted according to RFC2822.
There are a couple things to consider:
- This method is allocating;
- The length of the resulting string will either be
30
or31
depending on whether the day is double-digit;
§Examples
use utc2k::Utc2k;
let date = Utc2k::new(2003, 7, 1, 10, 52, 37);
assert_eq!(date.to_rfc2822(), "Tue, 01 Jul 2003 10:52:37 +0000");
let date = Utc2k::new(2036, 12, 15, 16, 30, 55);
assert_eq!(date.to_rfc2822(), "Mon, 15 Dec 2036 16:30:55 +0000");
sourcepub fn from_rfc2822<S>(src: S) -> Option<Self>
pub fn from_rfc2822<S>(src: S) -> Option<Self>
§From RFC2822.
This method can be used to construct a Utc2k
from an RFC2822-formatted
string. Variations with and without a leading weekday, and with and
without a trailing offset, are supported. If an offset is included, the
datetime will be adjusted accordingly to make it properly UTC.
Note: missing offsets are meant to imply “localized” time, but as this library has no timezone handling, strings without any “+HHMM” at the end will be parsed as if they were already in UTC.
§Examples
use utc2k::Utc2k;
assert_eq!(
Utc2k::from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0000"),
Some(Utc2k::new(2003, 7, 1, 10, 52, 37)),
);
assert_eq!(
Utc2k::from_rfc2822("Tue, 01 Jul 2003 10:52:37 +0000"),
Some(Utc2k::new(2003, 7, 1, 10, 52, 37)),
);
assert_eq!(
Utc2k::from_rfc2822("1 Jul 2003 10:52:37"),
Some(Utc2k::new(2003, 7, 1, 10, 52, 37)),
);
assert_eq!(
Utc2k::from_rfc2822("01 Jul 2003 10:52:37"),
Some(Utc2k::new(2003, 7, 1, 10, 52, 37)),
);
assert_eq!(
Utc2k::from_rfc2822("Tue, 10 Jul 2003 10:52:37 -0700"),
Some(Utc2k::new(2003, 7, 10, 17, 52, 37)),
);
assert_eq!(
Utc2k::from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0430"),
Some(Utc2k::new(2003, 7, 1, 6, 22, 37)),
);
sourcepub const fn to_midnight(self) -> Self
pub const fn to_midnight(self) -> Self
sourcepub fn with_time(self, hh: u8, mm: u8, ss: u8) -> Self
pub fn with_time(self, hh: u8, mm: u8, ss: u8) -> Self
§Change Time.
Return a new Utc2k
instance with the original date — unless there
is carry-over needed — and a new time.
§Examples
use utc2k::Utc2k;
let date = Utc2k::default();
assert_eq!(date.to_string(), "2000-01-01 00:00:00");
// Change the time bits.
assert_eq!(date.with_time(13, 14, 15).to_string(), "2000-01-01 13:14:15");
source§impl Utc2k
impl Utc2k
§Checked Operations.
sourcepub fn checked_add(self, secs: u32) -> Option<Self>
pub fn checked_add(self, secs: u32) -> Option<Self>
§Checked Add.
Return a new Utc2k
instance set n seconds into the future from
this one, returning none
(rather than saturating) on overflow.
If you’d rather saturate addition, you can just use std::ops::Add
.
§Examples
use utc2k::Utc2k;
let date = Utc2k::max();
assert!(date.checked_add(1).is_none());
let date = Utc2k::new(2010, 1, 1, 0, 0, 0);
let added = date.checked_add(86_413).unwrap();
assert_eq!(added.to_string(), "2010-01-02 00:00:13");
sourcepub fn checked_from_unixtime(src: u32) -> Result<Self, Utc2kError>
pub fn checked_from_unixtime(src: u32) -> Result<Self, Utc2kError>
§From Unixtime (Checked).
This can be used instead of the usual From<u32>
if you’d like to
trigger an error when the timestamp is out of range (rather than just
saturating it).
§Errors
An error will be returned if the timestamp is less than Utc2k::MIN_UNIXTIME
or greater than Utc2k::MAX_UNIXTIME
.
§Examples
use utc2k::Utc2k;
// Too old.
assert!(Utc2k::checked_from_unixtime(0).is_err());
// Too new.
assert!(Utc2k::checked_from_unixtime(u32::MAX).is_err());
// This fits.
assert!(Utc2k::checked_from_unixtime(Utc2k::MIN_UNIXTIME).is_ok());
sourcepub fn checked_sub(self, secs: u32) -> Option<Self>
pub fn checked_sub(self, secs: u32) -> Option<Self>
§Checked Sub.
Return a new Utc2k
instance set n seconds before this one,
returning none
(rather than saturating) on overflow.
If you’d rather saturate subtraction, you can just use std::ops::Sub
.
§Examples
use utc2k::Utc2k;
let date = Utc2k::min();
assert!(date.checked_sub(1).is_none());
let date = Utc2k::new(2010, 1, 1, 0, 0, 0);
let subbed = date.checked_sub(86_413).unwrap();
assert_eq!(subbed.to_string(), "2009-12-30 23:59:47");
source§impl Utc2k
impl Utc2k
§Comparison.
sourcepub fn abs_diff(self, other: Self) -> u32
pub fn abs_diff(self, other: Self) -> u32
§Absolute Difference.
This returns the (absolute) number of seconds between two datetimes.
§Examples.
use utc2k::Utc2k;
let date1 = Utc2k::new(2022, 10, 15, 11, 30, 0);
let date2 = Utc2k::new(2022, 10, 15, 11, 31, 0);
// ABS means the ordering does not matter.
assert_eq!(date1.abs_diff(date2), 60);
assert_eq!(date2.abs_diff(date1), 60);
// If the dates are equal, the difference is zero.
assert_eq!(date1.abs_diff(date1), 0);
// Because we're only dealing with a single century, there is an
// upper limit to the possible return values…
assert_eq!(Utc2k::min().abs_diff(Utc2k::max()), 3_155_759_999);
sourcepub fn cmp_date(self, other: Self) -> Ordering
pub fn cmp_date(self, other: Self) -> Ordering
§Compare (Only) Dates.
Compare self
to another Utc2k
instance, ignoring the time
components of each.
§Examples
use utc2k::Utc2k;
use std::cmp::Ordering;
// The times are different, but the dates match.
let date1 = Utc2k::new(2020, 3, 15, 0, 0, 0);
let date2 = Utc2k::new(2020, 3, 15, 16, 30, 20);
assert_eq!(date1.cmp_date(date2), Ordering::Equal);
// If the dates don't match, it's what you'd expect.
let date3 = Utc2k::new(2022, 10, 31, 0, 0, 0);
assert_eq!(date1.cmp_date(date3), Ordering::Less);
sourcepub fn cmp_time(self, other: Self) -> Ordering
pub fn cmp_time(self, other: Self) -> Ordering
§Compare (Only) Times.
Compare self
to another Utc2k
instance, ignoring the date
components of each.
§Examples
use utc2k::Utc2k;
use std::cmp::Ordering;
// The dates match, but the times are different.
let date1 = Utc2k::new(2020, 3, 15, 0, 0, 0);
let date2 = Utc2k::new(2020, 3, 15, 16, 30, 20);
assert_eq!(date1.cmp_time(date2), Ordering::Less);
// If the times match, it's what you'd expect.
let date3 = Utc2k::new(2022, 10, 31, 0, 0, 0);
assert_eq!(date1.cmp_time(date3), Ordering::Equal);
Trait Implementations§
source§impl AddAssign<u32> for Utc2k
impl AddAssign<u32> for Utc2k
source§fn add_assign(&mut self, other: u32)
fn add_assign(&mut self, other: u32)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Utc2k
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Utc2k
serde
only.source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
§Deserialize.
Use the optional serde
crate feature to enable serialization support.
source§impl From<LocalOffset> for Utc2k
impl From<LocalOffset> for Utc2k
source§fn from(src: LocalOffset) -> Self
fn from(src: LocalOffset) -> Self
source§impl From<Utc2k> for LocalOffset
impl From<Utc2k> for LocalOffset
source§impl From<u32> for Utc2k
impl From<u32> for Utc2k
source§fn from(src: u32) -> Self
fn from(src: u32) -> Self
§From Timestamp.
Note, this will saturate to Utc2k::MIN_UNIXTIME
and
Utc2k::MAX_UNIXTIME
if the timestamp is out of range.
§Examples
use utc2k::Utc2k;
assert_eq!(Utc2k::from(0).to_string(), "2000-01-01 00:00:00");
assert_eq!(Utc2k::from(u32::MAX).to_string(), "2099-12-31 23:59:59");
source§impl Ord for Utc2k
impl Ord for Utc2k
source§impl PartialEq for Utc2k
impl PartialEq for Utc2k
source§impl PartialOrd for Utc2k
impl PartialOrd for Utc2k
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Sub<u32> for Utc2k
impl Sub<u32> for Utc2k
source§fn sub(self, other: u32) -> Self
fn sub(self, other: u32) -> Self
§Subtraction.
This method returns a new Utc2k
object reduced by a given number of
seconds.
§Examples
use utc2k::Utc2k;
assert_eq!(
Utc2k::new(2020, 1, 5, 0, 0, 0) - 86_400_u32,
Utc2k::new(2020, 1, 4, 0, 0, 0),
);
assert_eq!(
Utc2k::new(2020, 1, 5, 0, 0, 0) - 86_399_u32,
Utc2k::new(2020, 1, 4, 0, 0, 1),
);
assert_eq!(
Utc2k::new(2020, 1, 5, 3, 10, 20) - 14_400_u32,
Utc2k::new(2020, 1, 4, 23, 10, 20),
);
assert_eq!(
Utc2k::new(2020, 1, 1, 3, 10, 20) - 14_400_u32,
Utc2k::new(2019, 12, 31, 23, 10, 20),
);
source§impl SubAssign<u32> for Utc2k
impl SubAssign<u32> for Utc2k
source§fn sub_assign(&mut self, other: u32)
fn sub_assign(&mut self, other: u32)
-=
operation. Read moresource§impl TryFrom<&[u8]> for Utc2k
impl TryFrom<&[u8]> for Utc2k
source§fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
§Parse Slice.
This will attempt to construct a Utc2k
from a date/time or date
slice. See Utc2k::from_datetime_str
and Utc2k::from_date_str
for more
information.
§Examples
use utc2k::Utc2k;
let date = Utc2k::try_from(&b"2021/06/25"[..]).unwrap();
assert_eq!(date.to_string(), "2021-06-25 00:00:00");
let date = Utc2k::try_from(&b"2021-06-25 13:15:25.0000"[..]).unwrap();
assert_eq!(date.to_string(), "2021-06-25 13:15:25");
assert!(Utc2k::try_from(&b"2021-06-applesauces"[..]).is_err());
§type Error = Utc2kError
type Error = Utc2kError
source§impl TryFrom<&OsStr> for Utc2k
impl TryFrom<&OsStr> for Utc2k
source§fn try_from(src: &OsStr) -> Result<Self, Self::Error>
fn try_from(src: &OsStr) -> Result<Self, Self::Error>
§From OsStr
.
use std::ffi::OsStr;
use utc2k::Utc2k;
assert_eq!(
Utc2k::try_from(OsStr::new("2013-12-15 21:30:02")).unwrap().to_string(),
"2013-12-15 21:30:02"
);
assert_eq!(
Utc2k::try_from(OsStr::new("2013-12-15")).unwrap().to_string(),
"2013-12-15 00:00:00"
);
§type Error = Utc2kError
type Error = Utc2kError
source§impl TryFrom<&str> for Utc2k
impl TryFrom<&str> for Utc2k
source§fn try_from(src: &str) -> Result<Self, Self::Error>
fn try_from(src: &str) -> Result<Self, Self::Error>
§Parse String.
This will attempt to construct a Utc2k
from a date/time or date
string. Parsing is naive; only the positions where numbers are
expected will be looked at.
String length is used to determine whether or not the value should be parsed as a full date/time (19) or just a date (10).
See Utc2k::from_datetime_str
and Utc2k::from_date_str
for more
information.
§Examples
use utc2k::Utc2k;
let date = Utc2k::try_from("2021/06/25").unwrap();
assert_eq!(date.to_string(), "2021-06-25 00:00:00");
let date = Utc2k::try_from("2021-06-25 13:15:25.0000").unwrap();
assert_eq!(date.to_string(), "2021-06-25 13:15:25");
// The `FromStr` impl is an alias of `TryFrom<&str>` so can be used to
// the same end:
let date2 = "2021-06-25 13:15:25.0000".parse::<Utc2k>().unwrap();
assert_eq!(date, date2);
// Really bad strings won't parse.
assert!(Utc2k::try_from("2021-06-applesauces").is_err());