@@ -25,32 +25,51 @@ use web_time::{SystemTime, UNIX_EPOCH};
25
25
#[ cfg( feature = "sys" ) ]
26
26
pub struct Temporal ;
27
27
28
- #[ cfg( feature = "sys" ) ]
29
28
impl Temporal {
30
29
/// Get a `Now` object for the default host system.
31
- pub fn now ( ) -> Now < DefaultHostSystem > {
32
- Now :: new ( DefaultHostSystem )
30
+ #[ cfg( feature = "sys-local" ) ]
31
+ #[ deprecated(
32
+ since = "0.1.0" ,
33
+ note = "`now` deprecated was not clear about the host system implementation, please use `local_now`"
34
+ ) ]
35
+ pub fn now ( ) -> Now < LocalHostSystem > {
36
+ Now :: new ( LocalHostSystem )
37
+ }
38
+
39
+ /// Get a `Now` object with a [`LocalHostSystem`], which
40
+ /// will use the host system's time zone as a fallback.
41
+ #[ cfg( feature = "sys-local" ) ]
42
+ pub fn local_now ( ) -> Now < LocalHostSystem > {
43
+ Now :: new ( LocalHostSystem )
44
+ }
45
+
46
+ /// Get a `Now` object with a [`UtcHostSystem`], which
47
+ /// will use a UTC time zone as a fallback.
48
+ #[ cfg( feature = "sys" ) ]
49
+ pub fn utc_now ( ) -> Now < UtcHostSystem > {
50
+ Now :: new ( UtcHostSystem )
33
51
}
34
52
}
35
53
36
- /// A default host system implementation
54
+ /// A UTC host system implementation that will return the current time
55
+ /// with the a UTC time zone as fallback.
37
56
///
38
- /// This implementation is backed by [`SystemTime`] and [`iana_time_zone`]
57
+ /// This implementation is backed by [`std::time:: SystemTime`].
39
58
#[ cfg( feature = "sys" ) ]
40
- pub struct DefaultHostSystem ;
59
+ pub struct UtcHostSystem ;
41
60
42
61
#[ cfg( feature = "sys" ) ]
43
- impl HostHooks for DefaultHostSystem { }
62
+ impl HostHooks for UtcHostSystem { }
44
63
45
64
#[ cfg( feature = "sys" ) ]
46
- impl HostClock for DefaultHostSystem {
65
+ impl HostClock for UtcHostSystem {
47
66
fn get_host_epoch_nanoseconds ( & self ) -> TemporalResult < EpochNanoseconds > {
48
67
get_system_nanoseconds ( )
49
68
}
50
69
}
51
70
52
71
#[ cfg( feature = "sys" ) ]
53
- impl HostTimeZone for DefaultHostSystem {
72
+ impl HostTimeZone for UtcHostSystem {
54
73
fn get_host_time_zone (
55
74
& self ,
56
75
provider : & impl timezone_provider:: provider:: TimeZoneProvider ,
@@ -59,7 +78,34 @@ impl HostTimeZone for DefaultHostSystem {
59
78
}
60
79
}
61
80
62
- #[ cfg( feature = "sys" ) ]
81
+ /// A local host system implementation that will return the current time
82
+ /// with the system time zone as a fallback.
83
+ ///
84
+ /// This implementation is backed by [`std::time::SystemTime`] and [`iana_time_zone`]
85
+ #[ cfg( feature = "sys-local" ) ]
86
+ pub struct LocalHostSystem ;
87
+
88
+ #[ cfg( feature = "sys-local" ) ]
89
+ impl HostHooks for LocalHostSystem { }
90
+
91
+ #[ cfg( feature = "sys-local" ) ]
92
+ impl HostClock for LocalHostSystem {
93
+ fn get_host_epoch_nanoseconds ( & self ) -> TemporalResult < EpochNanoseconds > {
94
+ get_system_nanoseconds ( )
95
+ }
96
+ }
97
+
98
+ #[ cfg( feature = "sys-local" ) ]
99
+ impl HostTimeZone for LocalHostSystem {
100
+ fn get_host_time_zone (
101
+ & self ,
102
+ provider : & impl timezone_provider:: provider:: TimeZoneProvider ,
103
+ ) -> TemporalResult < TimeZone > {
104
+ get_system_timezone ( provider)
105
+ }
106
+ }
107
+
108
+ #[ cfg( feature = "sys-local" ) ]
63
109
#[ inline]
64
110
pub ( crate ) fn get_system_timezone ( provider : & impl TimeZoneProvider ) -> TemporalResult < TimeZone > {
65
111
iana_time_zone:: get_timezone ( )
0 commit comments