You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(tick): implement display extension for SystemTime (#169)
I found multiple cases when the consumer wants to display `SystemTime`
but currently there is no way to do it easily. One can construct
`Iso8601` from SystemTime manually that implements the `Display` but
it's too verbose.
This PR adds an `display` extension to simplify the scenario. To fulfill
the format requirements we do not fail of `SystemTime` is out of range,
but rather display values saturated at boundaries
`-009999-01-02T01:59:59Z` and `9999-12-30T22:00:00.999999999Z`.
This is because we are limited by the jiff MIN/MAX values.
Before:
```rust
println!("Current time: {}", Iso8601::try_from(clock.system_time()).unwrap_or(Iso8601::MAX));
```
After:
```rust
println!("Current time: {}", clock.system_time().display_iso_8601());
```
Copy file name to clipboardExpand all lines: crates/tick/README.md
+43-37Lines changed: 43 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,12 +75,16 @@ in production and tests, with zero runtime overhead when `test-util` is disabled
75
75
*[`Stopwatch`][__link4] - Measures elapsed time.
76
76
*[`Delay`][__link5] - Delays the execution for a specified duration.
77
77
*[`PeriodicTimer`][__link6] - Schedules a task to run periodically.
78
-
*[`FutureExt`][__link7] - Extensions for the `Future` trait.
79
-
*[`Error`][__link8] - Represents an error that can occur when working with time. Provides limited
78
+
*[`Error`][__link7] - Represents an error that can occur when working with time. Provides limited
80
79
introspection capabilities.
81
-
*[`fmt`][__link9] - Utilities for formatting `SystemTime` into various formats. Available when
80
+
*[`fmt`][__link8] - Utilities for formatting `SystemTime` into various formats. Available when
82
81
the `fmt` feature is enabled.
83
-
*[`runtime`][__link10] - Infrastructure for integrating time primitives into async runtimes.
82
+
*[`runtime`][__link9] - Infrastructure for integrating time primitives into async runtimes.
83
+
84
+
## Extensions
85
+
86
+
*[`FutureExt`][__link10] - Extensions for the `Future` trait, providing timeout functionality.
87
+
*[`SystemTimeExt`][__link11] - Extensions for [`SystemTime`][__link12].
84
88
85
89
## Machine-Centric vs. Human-Centric Time
86
90
@@ -94,7 +98,7 @@ When working with time, two different use cases are considered:
94
98
Dealing with human-centric time involves significant ambiguity.
95
99
96
100
This crate is designed for machine-centric time. For human-centric time manipulation,
97
-
consider using other crates such as [jiff][__link11], [chrono][__link12], or [time][__link13]. The time primitives in
101
+
consider using other crates such as [jiff][__link13], [chrono][__link14], or [time][__link15]. The time primitives in
98
102
this crate are designed for easy interoperability with these crates. See the `time_interop*`
99
103
examples for more details.
100
104
@@ -110,7 +114,7 @@ type, which is exposed when the `test-util` feature is enabled.
110
114
111
115
### Use `Clock` to retrieve absolute time
112
116
113
-
The clock provides absolute time as `SystemTime`. See [`Clock`][__link14] documentation for detailed
117
+
The clock provides absolute time as `SystemTime`. See [`Clock`][__link16] documentation for detailed
114
118
information.
115
119
116
120
```rust
@@ -129,7 +133,7 @@ assert!(time1 <= time2);
129
133
130
134
### Use `Clock` to retrieve relative time
131
135
132
-
The clock provides relative time via [`Clock::instant`][__link15] and [`Stopwatch`][__link16].
136
+
The clock provides relative time via [`Clock::instant`][__link17] and [`Stopwatch`][__link18].
133
137
134
138
```rust
135
139
usestd::time::{Duration, Instant};
@@ -184,18 +188,18 @@ timer
184
188
185
189
This crate provides several optional features that can be enabled in your `Cargo.toml`:
186
190
187
-
***`tokio`** - Integration with the [Tokio][__link17] runtime. Enables
188
-
[`Clock::new_tokio`][__link18] for creating clocks that use Tokio’s time facilities.
189
-
***`test-util`** - Enables the [`ClockControl`][__link19] type for controlling the passage of time
191
+
***`tokio`** - Integration with the [Tokio][__link19] runtime. Enables
192
+
[`Clock::new_tokio`][__link20] for creating clocks that use Tokio’s time facilities.
193
+
***`test-util`** - Enables the [`ClockControl`][__link21] type for controlling the passage of time
190
194
in tests. This allows you to pause time, advance it manually, or automatically advance
191
195
timers for fast, deterministic testing. **Only enable this in `dev-dependencies`.**
192
-
***`serde`** - Adds serialization and deserialization support via [serde][__link20].
193
-
***`fmt`** - Enables the [`fmt`][__link21] module with utilities for formatting `SystemTime` into
196
+
***`serde`** - Adds serialization and deserialization support via [serde][__link22].
197
+
***`fmt`** - Enables the [`fmt`][__link23] module with utilities for formatting `SystemTime` into
194
198
various formats (e.g., ISO 8601, RFC 2822).
195
199
196
200
## Additional Examples
197
201
198
-
The [time examples][__link22]
202
+
The [time examples][__link24]
199
203
contain additional examples of how to use the time primitives.
200
204
201
205
@@ -204,27 +208,29 @@ contain additional examples of how to use the time primitives.
204
208
This crate was developed as part of <ahref="../..">The Oxidizer Project</a>. Browse this crate's <ahref="https://github.com/microsoft/oxidizer/tree/main/crates/tick">source code</a>.
0 commit comments