File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ cannot be parsed as a relative time.
80
80
81
81
The ` from_str ` function returns:
82
82
83
- - ` Ok(DateTime<FixedOffset>) ` - If the input string can be prsed as a datetime
83
+ - ` Ok(DateTime<FixedOffset>) ` - If the input string can be parsed as a datetime
84
84
- ` Err(ParseDurationError::InvalidInput) ` - If the input string cannot be parsed
85
85
86
86
## Fuzzer
Original file line number Diff line number Diff line change @@ -235,6 +235,38 @@ mod tests {
235
235
}
236
236
}
237
237
238
+ #[ cfg( test) ]
239
+ mod timestamp {
240
+ use crate :: parse_datetime:: from_str;
241
+ use chrono:: { Utc , TimeZone } ;
242
+
243
+ #[ test]
244
+ fn test_positive_offsets ( ) {
245
+ let offsets: Vec < i64 > = vec ! [
246
+ 0 ,
247
+ 1 ,
248
+ 2 ,
249
+ 10 ,
250
+ 100 ,
251
+ 150 ,
252
+ 2000 ,
253
+ 1234400000 ,
254
+ 1334400000 ,
255
+ 1692582913 ,
256
+ 2092582910
257
+ ] ;
258
+
259
+ for offset in offsets {
260
+ let time = Utc . timestamp ( offset, 0 ) ;
261
+ let dt = from_str ( format ! ( "@{}" , offset) ) ;
262
+ assert_eq ! (
263
+ dt. unwrap( ) ,
264
+ time
265
+ ) ;
266
+ }
267
+ }
268
+ }
269
+
238
270
/// Used to test example code presented in the README.
239
271
mod readme_test {
240
272
use crate :: parse_datetime:: from_str;
Original file line number Diff line number Diff line change @@ -136,6 +136,14 @@ fn test_from_str_at_date_day() {
136
136
) ;
137
137
}
138
138
139
+ #[ test]
140
+ fn test_unix_timestamp ( ) {
141
+ let res = from_str ( "2004-02-29 16:21:42" ) ;
142
+
143
+ dbg ! ( res) ;
144
+
145
+ }
146
+
139
147
#[ test]
140
148
fn test_invalid_input_at_date ( ) {
141
149
let today = Utc :: now ( ) . date_naive ( ) ;
You can’t perform that action at this time.
0 commit comments