5
5
///
6
6
/// Notable default implementations of this trait are [LocalDateTime] and `()`.
7
7
/// The former prints the current time as reported by [time's OffsetDateTime]
8
- /// (note that it may panic! make sure to check out the docs for the [LocalDateTime]),
8
+ /// (note that it requires a `time` feature to be enabled and may panic!
9
+ /// make sure to check out the docs for the [LocalDateTime]),
9
10
/// and the latter does not print the current time at all.
10
11
///
11
12
/// Inspired by the [FormatTime] trait from [tracing-subscriber].
@@ -34,9 +35,11 @@ impl FormatTime for () {
34
35
////////////////////////////////////////////////////////////////////////////////////////////////////
35
36
36
37
/// Retrieve and print the current wall-clock time in UTC timezone.
38
+ #[ cfg( feature = "time" ) ]
37
39
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
38
40
pub struct UtcDateTime ;
39
41
42
+ #[ cfg( feature = "time" ) ]
40
43
impl FormatTime for UtcDateTime {
41
44
fn format_time ( & self , w : & mut impl std:: fmt:: Write ) -> std:: fmt:: Result {
42
45
let time = time:: OffsetDateTime :: now_utc ( ) ;
@@ -56,9 +59,11 @@ impl FormatTime for UtcDateTime {
56
59
// NB:
57
60
// Can't use `tracing_subscriber::fmt::time::SystemTime` since it uses
58
61
// private `datetime` module to format the actual time.
62
+ #[ cfg( feature = "time" ) ]
59
63
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
60
64
pub struct LocalDateTime ;
61
65
66
+ #[ cfg( feature = "time" ) ]
62
67
impl FormatTime for LocalDateTime {
63
68
fn format_time ( & self , w : & mut impl std:: fmt:: Write ) -> std:: fmt:: Result {
64
69
let time = time:: OffsetDateTime :: now_local ( ) . expect ( "time offset cannot be determined" ) ;
0 commit comments