55///
66/// Notable default implementations of this trait are [LocalDateTime] and `()`.
77/// 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]),
910/// and the latter does not print the current time at all.
1011///
1112/// Inspired by the [FormatTime] trait from [tracing-subscriber].
@@ -34,9 +35,11 @@ impl FormatTime for () {
3435////////////////////////////////////////////////////////////////////////////////////////////////////
3536
3637/// Retrieve and print the current wall-clock time in UTC timezone.
38+ #[ cfg( feature = "time" ) ]
3739#[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
3840pub struct UtcDateTime ;
3941
42+ #[ cfg( feature = "time" ) ]
4043impl FormatTime for UtcDateTime {
4144 fn format_time ( & self , w : & mut impl std:: fmt:: Write ) -> std:: fmt:: Result {
4245 let time = time:: OffsetDateTime :: now_utc ( ) ;
@@ -56,9 +59,11 @@ impl FormatTime for UtcDateTime {
5659// NB:
5760// Can't use `tracing_subscriber::fmt::time::SystemTime` since it uses
5861// private `datetime` module to format the actual time.
62+ #[ cfg( feature = "time" ) ]
5963#[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
6064pub struct LocalDateTime ;
6165
66+ #[ cfg( feature = "time" ) ]
6267impl FormatTime for LocalDateTime {
6368 fn format_time ( & self , w : & mut impl std:: fmt:: Write ) -> std:: fmt:: Result {
6469 let time = time:: OffsetDateTime :: now_local ( ) . expect ( "time offset cannot be determined" ) ;
0 commit comments