Struct utc2k::Utc2k

source ·
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

§Min/Max.
source

pub const MIN_UNIXTIME: u32 = 946_684_800u32

§Minimum Timestamp.
source

pub const MAX_UNIXTIME: u32 = 4_102_444_799u32

§Maximum Timestamp.
source

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

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");
source§

impl Utc2k

§Instantiation.
source

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

pub fn now() -> Self

§Now.

Create a new instance representing the current UTC time.

source

pub fn now_local() -> Self

Available on crate feature 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

pub fn tomorrow() -> Self

§Tomorrow.

Create a new instance representing one day from now (present time).

§Examples
use utc2k::Utc2k;

assert_eq!(Utc2k::tomorrow(), Utc2k::now() + 86_400_u32);
source

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);
source§

impl Utc2k

§String Parsing.
source

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.

source

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.

source

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.

source

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.

source

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).

source§

impl Utc2k

§Get Parts.
source

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));
source

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));
source

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));
source

pub const fn year(self) -> u16

§Year.

This returns the year value.

§Examples
use utc2k::Utc2k;

let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.year(), 2010);
source

pub const fn month(self) -> u8

§Month.

This returns the month value.

§Examples
use utc2k::Utc2k;

let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.month(), 5);
source

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);
source

pub const fn day(self) -> u8

§Day.

This returns the day value.

§Examples
use utc2k::Utc2k;

let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.day(), 15);
source

pub const fn hour(self) -> u8

§Hour.

This returns the hour value.

§Examples
use utc2k::Utc2k;

let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.hour(), 16);
source

pub const fn minute(self) -> u8

§Minute.

This returns the minute value.

§Examples
use utc2k::Utc2k;

let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.minute(), 30);
source

pub const fn second(self) -> u8

§Second.

This returns the second value.

§Examples
use utc2k::Utc2k;

let date = Utc2k::new(2010, 5, 15, 16, 30, 1);
assert_eq!(date.second(), 1);
source§

impl Utc2k

§Other Getters.
source

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());
source

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

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

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);
source

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);
source

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

pub fn weekday(self) -> Weekday

§Weekday.

Return the Weekday corresponding to the given date.

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

let date = Utc2k::try_from("2021-07-08 13:22:01").unwrap();
assert_eq!(date.weekday(), Weekday::Thursday);
assert_eq!(date.weekday().as_ref(), "Thursday");
source§

impl Utc2k

§Conversion.
source

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));
source

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

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 or 31 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");
source

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)),
);
source

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));
source

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);
source

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

§Checked Operations.
source

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

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());
source

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

§Comparison.

source

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);
source

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);
source

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 Add<u32> for Utc2k

§

type Output = Utc2k

The resulting type after applying the + operator.
source§

fn add(self, other: u32) -> Self

Performs the + operation. Read more
source§

impl AddAssign<u32> for Utc2k

source§

fn add_assign(&mut self, other: u32)

Performs the += operation. Read more
source§

impl Clone for Utc2k

source§

fn clone(&self) -> Utc2k

Returns a copy 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 Utc2k

source§

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

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

impl Default for Utc2k

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Utc2k

Available on crate feature serde only.
source§

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 Display for Utc2k

source§

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

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

impl From<&FmtUtc2k> for Utc2k

source§

fn from(src: &FmtUtc2k) -> Self

Converts to this type from the input type.
source§

impl From<&Utc2k> for FmtUtc2k

source§

fn from(src: &Utc2k) -> Self

Converts to this type from the input type.
source§

impl From<FmtUtc2k> for Utc2k

source§

fn from(src: FmtUtc2k) -> Self

Converts to this type from the input type.
source§

impl From<LocalOffset> for Utc2k

source§

fn from(src: LocalOffset) -> Self

Converts to this type from the input type.
source§

impl From<Utc2k> for FmtUtc2k

source§

fn from(src: Utc2k) -> Self

Converts to this type from the input type.
source§

impl From<Utc2k> for LocalOffset

source§

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!

source§

impl From<Utc2k> for Month

source§

fn from(src: Utc2k) -> Self

Converts to this type from the input type.
source§

impl From<Utc2k> for Weekday

source§

fn from(src: Utc2k) -> Self

Converts to this type from the input type.
source§

impl From<Utc2k> for u32

source§

fn from(src: Utc2k) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Utc2k

source§

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 FromStr for Utc2k

§

type Err = Utc2kError

The associated error which can be returned from parsing.
source§

fn from_str(src: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Utc2k

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 Utc2k

source§

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

§Compare.

Compare two dates.

§Examples
use utc2k::Utc2k;

let date1 = Utc2k::new(2020, 10, 15, 20, 25, 30);
let date2 = Utc2k::new(2020, 10, 15, 0, 0, 0);
let date3 = Utc2k::new(2022, 10, 15, 0, 0, 0);

assert!(date1 > date2);
assert!(date1 < date3);
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 + PartialOrd,

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

impl PartialEq for Utc2k

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Utc2k

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Utc2k

Available on crate feature serde only.
source§

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.

source§

impl Sub<u32> for Utc2k

source§

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),
);
§

type Output = Utc2k

The resulting type after applying the - operator.
source§

impl SubAssign<u32> for Utc2k

source§

fn sub_assign(&mut self, other: u32)

Performs the -= operation. Read more
source§

impl TryFrom<&[u8]> for Utc2k

source§

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

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

impl TryFrom<&OsStr> for Utc2k

source§

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

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

impl TryFrom<&str> for Utc2k

source§

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());
§

type Error = Utc2kError

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

impl TryFrom<i32> for Utc2k

§

type Error = Utc2kError

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

fn try_from(src: i32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<i64> for Utc2k

§

type Error = Utc2kError

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

fn try_from(src: i64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<isize> for Utc2k

§

type Error = Utc2kError

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

fn try_from(src: isize) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u64> for Utc2k

§

type Error = Utc2kError

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

fn try_from(src: u64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<usize> for Utc2k

§

type Error = Utc2kError

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

fn try_from(src: usize) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Utc2k

source§

impl Eq for Utc2k

source§

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§

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> 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,

§

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§

default 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>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,