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>
.
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
sourceimpl Utc2k
impl Utc2k
sourcepub const MIN_UNIXTIME: u32 = 946_684_800u32
pub const MIN_UNIXTIME: u32 = 946_684_800u32
sourcepub const MAX_UNIXTIME: u32 = 4_102_444_799u32
pub const MAX_UNIXTIME: u32 = 4_102_444_799u32
sourcepub const fn min() -> Self
pub const fn min() -> Self
Minimum Value.
This is equivalent to 2000-01-01 00:00:00
.
Examples
use utc2k::Utc2k;
let date = Utc2k::min();
assert_eq!(date.to_string(), "2000-01-01 00:00:00");
sourcepub const fn max() -> Self
pub const fn max() -> Self
Maximum Value.
This is equivalent to 2099-12-31 23:59:59
.
Examples
use utc2k::Utc2k;
let date = Utc2k::max();
assert_eq!(date.to_string(), "2099-12-31 23:59:59");
sourceimpl Utc2k
impl Utc2k
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.
sourcepub fn yesterday() -> Self
pub fn yesterday() -> Self
Yesterday.
Create a new instance representing one day ago (present time).
Examples
use utc2k::Utc2k;
assert_eq!(Utc2k::yesterday(), Utc2k::now() - 86_400_u32);
sourceimpl Utc2k
impl Utc2k
sourcepub fn from_datetime_str<B>(src: B) -> Result<Self, Utc2kError>where
B: AsRef<[u8]>,
pub fn from_datetime_str<B>(src: B) -> Result<Self, Utc2kError>where
B: AsRef<[u8]>,
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>where
B: AsRef<[u8]>,
pub fn from_smooshed_datetime_str<B>(src: B) -> Result<Self, Utc2kError>where
B: AsRef<[u8]>,
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>where
B: AsRef<[u8]>,
pub fn from_date_str<B>(src: B) -> Result<Self, Utc2kError>where
B: AsRef<[u8]>,
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>where
B: AsRef<[u8]>,
pub fn from_smooshed_date_str<B>(src: B) -> Result<Self, Utc2kError>where
B: AsRef<[u8]>,
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>where
B: AsRef<[u8]>,
pub fn parse_time_str<B>(src: B) -> Result<(u8, u8, u8), Utc2kError>where
B: AsRef<[u8]>,
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).
sourceimpl Utc2k
impl Utc2k
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
Month (enum).
This returns the month value as a Month
.
Examples
use utc2k::{Month, Utc2k};
let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.month_enum(), Month::May);
sourceimpl Utc2k
impl Utc2k
sourcepub const fn leap_year(self) -> bool
pub const fn leap_year(self) -> bool
Is Leap Year?
This returns true
if this date is/was in a leap year.
Examples
use utc2k::Utc2k;
let date = Utc2k::try_from("2020-05-10 00:00:00").unwrap();
assert!(date.leap_year());
let date = Utc2k::try_from("2021-03-15 00:00:00").unwrap();
assert!(! date.leap_year());
sourcepub const fn month_abbreviation(self) -> &'static str
pub const fn month_abbreviation(self) -> &'static str
Abbreviated Month Name.
Return the abbreviated name of the month, nice and pretty.
Examples
use utc2k::Utc2k;
let date = Utc2k::try_from("2020-06-24 20:19:30").unwrap();
assert_eq!(date.month_abbreviation(), "Jun");
sourcepub const fn month_name(self) -> &'static str
pub const fn month_name(self) -> &'static str
Month Name.
Return the name of the month, nice and pretty.
Examples
use utc2k::Utc2k;
let date = Utc2k::try_from("2020-06-24 20:19:30").unwrap();
assert_eq!(date.month_name(), "June");
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);
sourceimpl Utc2k
impl Utc2k
sourcepub fn formatted(self) -> FmtUtc2k
pub fn formatted(self) -> FmtUtc2k
Formatted.
This returns a FmtUtc2k
and is equivalent to calling
FmtUtc2k::from(self)
.
Examples
use utc2k::{FmtUtc2k, Utc2k};
let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.formatted(), FmtUtc2k::from(date));
sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
To RFC3339.
Return a string formatted according to RFC3339.
Note: this method is allocating.
Examples
use utc2k::Utc2k;
let date = Utc2k::new(2021, 12, 13, 11, 56, 1);
assert_eq!(date.to_rfc3339(), "2021-12-13T11:56:01Z");
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>where
S: AsRef<str>,
pub fn from_rfc2822<S>(src: S) -> Option<Self>where
S: AsRef<str>,
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
To Midnight.
Return a new instance with zeroed-out time pieces, i.e. truncated to the date’s midnight.
Examples
use utc2k::Utc2k;
let date1 = Utc2k::new(2022, 7, 22, 20, 52, 41);
assert_eq!(date1.to_midnight(), date1.with_time(0, 0, 0));
sourcepub fn unixtime(self) -> u32
pub fn unixtime(self) -> u32
Unix Timestamp.
Return the unix timestamp for this object.
Examples
use utc2k::Utc2k;
let date = Utc2k::default(); // 2000-01-01 00:00:00
assert_eq!(date.unixtime(), Utc2k::MIN_UNIXTIME);
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");
sourceimpl Utc2k
impl Utc2k
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");
sourceimpl Utc2k
impl Utc2k
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
sourceimpl AddAssign<u32> for Utc2k
impl AddAssign<u32> for Utc2k
sourcefn add_assign(&mut self, other: u32)
fn add_assign(&mut self, other: u32)
Performs the +=
operation. Read more
sourceimpl<'de> Deserialize<'de> for Utc2k
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Utc2k
serde
only.sourcefn 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.
sourceimpl From<LocalOffset> for Utc2k
impl From<LocalOffset> for Utc2k
sourcefn from(src: LocalOffset) -> Self
fn from(src: LocalOffset) -> Self
Converts to this type from the input type.
sourceimpl From<Utc2k> for LocalOffset
impl From<Utc2k> for LocalOffset
sourcefn from(src: Utc2k) -> Self
fn from(src: Utc2k) -> Self
From Utc2k
Warning: this should only be used for Utc2k
instances holding honest
UTC datetimes. If you call this on a tricked/local instance, the offset
will get applied twice!
sourceimpl From<u32> for Utc2k
impl From<u32> for Utc2k
sourcefn 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");
sourceimpl Ord for Utc2k
impl Ord for Utc2k
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Utc2k> for Utc2k
impl PartialEq<Utc2k> for Utc2k
sourceimpl PartialOrd<Utc2k> for Utc2k
impl PartialOrd<Utc2k> for Utc2k
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Serialize for Utc2k
Available on crate feature serde
only.
impl Serialize for Utc2k
serde
only.sourcefn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serialize.
Use the optional serde
crate feature to enable serialization support.
sourceimpl Sub<u32> for Utc2k
impl Sub<u32> for Utc2k
sourcefn 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),
);
sourceimpl SubAssign<u32> for Utc2k
impl SubAssign<u32> for Utc2k
sourcefn sub_assign(&mut self, other: u32)
fn sub_assign(&mut self, other: u32)
Performs the -=
operation. Read more
sourceimpl TryFrom<&[u8]> for Utc2k
impl TryFrom<&[u8]> for Utc2k
sourcefn 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
The type returned in the event of a conversion error.
sourceimpl TryFrom<&OsStr> for Utc2k
impl TryFrom<&OsStr> for Utc2k
sourcefn 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
The type returned in the event of a conversion error.
sourceimpl TryFrom<&str> for Utc2k
impl TryFrom<&str> for Utc2k
sourcefn 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");
assert!(Utc2k::try_from("2021-06-applesauces").is_err());
type Error = Utc2kError
type Error = Utc2kError
The type returned in the event of a conversion error.
impl Copy for Utc2k
impl Eq for Utc2k
impl StructuralEq for Utc2k
impl StructuralPartialEq for Utc2k
Auto Trait Implementations
impl RefUnwindSafe for Utc2k
impl Send for Utc2k
impl Sync for Utc2k
impl Unpin for Utc2k
impl UnwindSafe for Utc2k
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more