1pub use std::time::SystemTime as Time;
4pub use time::UtcDateTime;
5
6#[cfg(not(feature = "web"))]
7pub use std::time::{Duration, Instant};
8#[cfg(feature = "web")]
9pub use web_time::{Duration, Instant};
10
11pub fn utc_now() -> UtcDateTime {
13 now().into()
14}
15
16#[cfg(any(feature = "system", feature = "web"))]
18pub fn now() -> Time {
19 #[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
20 {
21 Time::now()
22 }
23 #[cfg(all(target_family = "wasm", target_os = "unknown"))]
24 {
25 use web_time::web::SystemTimeExt;
26 web_time::SystemTime::now().to_std()
27 }
28}
29
30#[cfg(not(any(feature = "system", feature = "web")))]
32pub fn now() -> Time {
33 Time::UNIX_EPOCH
34}
35
36pub trait ToUtcDateTime {
38 fn to_utc_datetime(self) -> Option<UtcDateTime>;
40}
41
42impl ToUtcDateTime for i64 {
43 fn to_utc_datetime(self) -> Option<UtcDateTime> {
45 UtcDateTime::from_unix_timestamp(self).ok()
46 }
47}
48
49impl ToUtcDateTime for Time {
50 fn to_utc_datetime(self) -> Option<UtcDateTime> {
52 Some(UtcDateTime::from(self))
53 }
54}
55
56#[cfg(feature = "typst")]
58pub fn to_typst_time(timestamp: UtcDateTime) -> typst::foundations::Datetime {
59 let datetime = ::time::PrimitiveDateTime::new(timestamp.date(), timestamp.time());
60 typst::foundations::Datetime::Datetime(datetime)
61}