pub trait IntTime: Display + Into<u64> {
// Provided methods
fn unix<T: Time>(self) -> T { ... }
fn windows_ns<T: Time>(self) -> T { ... }
fn webkit<T: Time>(self) -> T { ... }
fn mac_os<T: Time>(self) -> T { ... }
fn mac_os_cfa<T: Time>(self) -> T { ... }
fn sas_4gl<T: Time>(self) -> T { ... }
fn ts_print(self) -> String { ... }
}Expand description
Provides wrappers on integer std types to parse into time structs, and also to pretty print timestamp integers
Note: If there is an error, the function will return the Unix epoch time for the struct of choice
You can only convert from positive integers, as negative integers are not supported, as they cannot be represented in the time structs. While it would be possible to fix this, I don’t think it is a needed feature at the moment.
Provided Methods§
Sourcefn unix<T: Time>(self) -> T
fn unix<T: Time>(self) -> T
Convert an integer into a time struct of choice
§Examples
use thetime::{System, Time, IntTime};
assert_eq!(1483228800u32.unix::<System>().pretty(), "2017-01-01 00:00:00");Sourcefn windows_ns<T: Time>(self) -> T
fn windows_ns<T: Time>(self) -> T
Convert an integer into a time struct of choice, from a Windows timestamp (100ns since 1601-01-01 00:00:00)
§Examples
use thetime::{System, Time, IntTime};
assert_eq!(131277024000000000u64.windows_ns::<System>().pretty(),"2017-01-01 00:00:00");Sourcefn webkit<T: Time>(self) -> T
fn webkit<T: Time>(self) -> T
Convert an integer into a time struct of choice, from a Webkit timestamp (microseconds since 1601-01-01 00:00:00)
§Examples
use thetime::{System, Time, IntTime};
println!("2017 - {:#?}", 13127702400000000u64.webkit::<System>());
assert_eq!(13127702400000000u64.webkit::<System>().strftime("%Y-%m-%d %H:%M:%S"), "2017-01-01 00:00:00");Sourcefn mac_os<T: Time>(self) -> T
fn mac_os<T: Time>(self) -> T
Convert an integer into a time struct of choice, from a Mac OS timestamp (seconds since 1904-01-01 00:00:00)
§Examples
use thetime::{System, Time, IntTime};
println!("2024 - {:#?}", 3787310789u64.mac_os::<System>());
assert_eq!(3787310789u64.mac_os::<System>().strftime("%Y-%m-%d %H:%M:%S"), "2024-01-05 14:46:29");Sourcefn mac_os_cfa<T: Time>(self) -> T
fn mac_os_cfa<T: Time>(self) -> T
Convert an integer into a time struct of choice, from a Mac OS Absolute timestamp (seconds since 2001-01-01 00:00:00)
§Examples
use thetime::{System, Time, IntTime};
println!("2024 - {:#?}", 726158877u64.mac_os_cfa::<System>());
assert_eq!(726158877u64.mac_os_cfa::<System>().strftime("%Y-%m-%d %H:%M:%S"), "2024-01-05 14:47:57");Sourcefn sas_4gl<T: Time>(self) -> T
fn sas_4gl<T: Time>(self) -> T
Convert an integer into a time struct of choice, from a SAS 4GL timestamp (seconds since 1960-01-01 00:00:00)
§Examples
use thetime::{System, Time, IntTime};
println!("2024 - {:#?}", 2020003754u64.sas_4gl::<System>());
assert_eq!(2020003754u64.sas_4gl::<System>().strftime("%Y-%m-%d %H:%M:%S"), "2024-01-04 16:09:14");Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.