@@ -28,13 +28,38 @@ impl Default for ChronoFmtType {
28
28
}
29
29
}
30
30
31
- /// Retrieve and print the current local time.
31
+ /// Formats the current [local time] using a [formatter] from the [`chrono`] crate.
32
+ ///
33
+ /// [local time]: chrono::Local::now()
34
+ /// [formatter]: chrono::format
32
35
#[ cfg_attr( docsrs, doc( cfg( feature = "chrono" ) ) ) ]
33
36
#[ derive( Debug , Clone , Eq , PartialEq , Default ) ]
34
37
pub struct ChronoLocal {
35
38
format : ChronoFmtType ,
36
39
}
37
40
41
+ impl ChronoLocal {
42
+ /// Format the time using the [`RFC 3339`] format
43
+ /// (a subset of [`ISO 8601`]).
44
+ ///
45
+ /// [`RFC 3339`]: https://tools.ietf.org/html/rfc3339
46
+ /// [`ISO 8601`]: https://en.wikipedia.org/wiki/ISO_8601
47
+ pub fn rfc_3339 ( ) -> Self {
48
+ Self {
49
+ format : ChronoFmtType :: Rfc3339 ,
50
+ }
51
+ }
52
+
53
+ /// Format the time using the given format string.
54
+ ///
55
+ /// See [`chrono::format::strftime`] for details on the supported syntax.
56
+ pub fn new ( format_string : String ) -> Self {
57
+ Self {
58
+ format : ChronoFmtType :: Custom ( format_string) ,
59
+ }
60
+ }
61
+ }
62
+
38
63
impl FormatTime for ChronoLocal {
39
64
fn format_time ( & self , w : & mut Writer < ' _ > ) -> alloc:: fmt:: Result {
40
65
let t = chrono:: Local :: now ( ) ;
@@ -45,13 +70,38 @@ impl FormatTime for ChronoLocal {
45
70
}
46
71
}
47
72
48
- /// Retrieve and print the current UTC time.
73
+ /// Formats the current [UTC time] using a [formatter] from the [`chrono`] crate.
74
+ ///
75
+ /// [UTC time]: chrono::Utc::now()
76
+ /// [formatter]: chrono::format
49
77
#[ cfg_attr( docsrs, doc( cfg( feature = "chrono" ) ) ) ]
50
78
#[ derive( Debug , Clone , Eq , PartialEq , Default ) ]
51
79
pub struct ChronoUtc {
52
80
format : ChronoFmtType ,
53
81
}
54
82
83
+ impl ChronoUtc {
84
+ /// Format the time using the [`RFC 3339`] format
85
+ /// (a subset of [`ISO 8601`]).
86
+ ///
87
+ /// [`RFC 3339`]: https://tools.ietf.org/html/rfc3339
88
+ /// [`ISO 8601`]: https://en.wikipedia.org/wiki/ISO_8601
89
+ pub fn rfc_3339 ( ) -> Self {
90
+ Self {
91
+ format : ChronoFmtType :: Rfc3339 ,
92
+ }
93
+ }
94
+
95
+ /// Format the time using the given format string.
96
+ ///
97
+ /// See [`chrono::format::strftime`] for details on the supported syntax.
98
+ pub fn new ( format_string : String ) -> Self {
99
+ Self {
100
+ format : ChronoFmtType :: Custom ( format_string) ,
101
+ }
102
+ }
103
+ }
104
+
55
105
impl FormatTime for ChronoUtc {
56
106
fn format_time ( & self , w : & mut Writer < ' _ > ) -> alloc:: fmt:: Result {
57
107
let t = chrono:: Utc :: now ( ) ;
0 commit comments