Struct PostEpochTime

Source
pub struct PostEpochTime { /* private fields */ }
Expand description

Conceptually this is a thin wrapper for std::time::SystemTime, but provides more useful functions. The impl of this struct has functions that allow easily extracting the year/month/date/etc. for the given point in time. In actual fact the internal representation of this struct is a Duration since the unix epoch, so that error-handling is only required once upon creating the instance, and not for each attempt at extracting date/time fields.

Implementations§

Source§

impl PostEpochTime

Source

pub fn from(st: &SystemTime) -> Result<Self, SystemTimeError>

Create a PostEpochTime from a SystemTime. The SystemTime must be temporally in the future relative to the unix epoch, or an error will be returned.

Source

pub fn now() -> Result<Self, SystemTimeError>

Create a PostEpochTime for the current instant. The current instant must be in the future relative to the unix epoch, or an error will be returned.

Examples found in repository?
examples/pretty_now.rs (line 4)
3fn main() {
4    println!("It is now {} in the UTC timezone", PostEpochTime::now().unwrap());
5}
More examples
Hide additional examples
examples/year_days.rs (line 4)
3fn main() {
4    let now = PostEpochTime::now().unwrap();
5    println!("The current year is {}, which has {} days", now.year(), days_in_year(now.year()));
6}
Source

pub fn milliseconds_since_epoch(&self) -> u128

Returns the number of milliseconds passed since the unix epoch.

Source

pub fn microseconds_since_epoch(&self) -> u128

Returns the number of microseconds passed since the unix epoch.

Source

pub fn nanoseconds_since_epoch(&self) -> u128

Returns the number of nanoseconds passed since the unix epoch.

Source

pub fn seconds_since_epoch(&self) -> u64

Returns the number of complete seconds passed since the unix epoch.

Source

pub fn days_since_epoch(&self) -> u64

Returns the number of complete days passed since the unix epoch.

Source

pub fn day_of_week(&self) -> Day

Returns the day of the week that this point in time falls on.

Source

pub fn year(&self) -> u64

Returns the year (e.g. 2020) this point in time falls on.

Examples found in repository?
examples/year_days.rs (line 5)
3fn main() {
4    let now = PostEpochTime::now().unwrap();
5    println!("The current year is {}, which has {} days", now.year(), days_in_year(now.year()));
6}
Source

pub fn day_of_year(&self) -> u64

Returns the day of the year for this point in time (1-indexed). A return value of 1 indicates January 1, a value of 2 indicates January 2, and so on. If the year is a leap year the largest returned value would be 366, and for non-leap years it would be 365.

Source

pub fn month(&self) -> Month

Returns the month this point in time falls on.

Source

pub fn day_of_month(&self) -> u64

Returns the day of the month for this point in time (1-indexed). A return value of 1 means it falls on the first of the month. The maximum returned value will be 31.

Source

pub fn second_in_day(&self) -> u64

Returns the second within the day (0-indexed). This will be in the range 0..86399 (inclusive).

Source

pub fn hour(&self) -> u64

Returns the hour within the day (0-indexed). This will be in the range 0..23 (inclusive).

Source

pub fn second_in_hour(&self) -> u64

Returns the second within the hour (0-indexed). This will be in the range 0..3599 (inclusive).

Source

pub fn minute(&self) -> u64

Returns the minute within the hour (0-indexed). This will be in the range 0..59 (inclusive).

Source

pub fn second(&self) -> u64

Returns the second within the minute (0-indexed). This will be in the range 0..59 (inclusive).

Trait Implementations§

Source§

impl Display for PostEpochTime

Source§

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

Formats the value using the given formatter. Read more

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