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
impl PostEpochTime
Sourcepub fn from(st: &SystemTime) -> Result<Self, SystemTimeError>
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.
Sourcepub fn now() -> Result<Self, SystemTimeError>
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?
More examples
Sourcepub fn milliseconds_since_epoch(&self) -> u128
pub fn milliseconds_since_epoch(&self) -> u128
Returns the number of milliseconds passed since the unix epoch.
Sourcepub fn microseconds_since_epoch(&self) -> u128
pub fn microseconds_since_epoch(&self) -> u128
Returns the number of microseconds passed since the unix epoch.
Sourcepub fn nanoseconds_since_epoch(&self) -> u128
pub fn nanoseconds_since_epoch(&self) -> u128
Returns the number of nanoseconds passed since the unix epoch.
Sourcepub fn seconds_since_epoch(&self) -> u64
pub fn seconds_since_epoch(&self) -> u64
Returns the number of complete seconds passed since the unix epoch.
Sourcepub fn days_since_epoch(&self) -> u64
pub fn days_since_epoch(&self) -> u64
Returns the number of complete days passed since the unix epoch.
Sourcepub fn day_of_week(&self) -> Day
pub fn day_of_week(&self) -> Day
Returns the day of the week that this point in time falls on.
Sourcepub fn day_of_year(&self) -> u64
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.
Sourcepub fn day_of_month(&self) -> u64
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.
Sourcepub fn second_in_day(&self) -> u64
pub fn second_in_day(&self) -> u64
Returns the second within the day (0-indexed). This will be in the range 0..86399 (inclusive).
Sourcepub fn hour(&self) -> u64
pub fn hour(&self) -> u64
Returns the hour within the day (0-indexed). This will be in the range 0..23 (inclusive).
Sourcepub fn second_in_hour(&self) -> u64
pub fn second_in_hour(&self) -> u64
Returns the second within the hour (0-indexed). This will be in the range 0..3599 (inclusive).