File tree Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,14 @@ extern crate serde;
41
41
extern crate serde_yaml;
42
42
43
43
mod error;
44
- mod filters;
45
44
mod parser;
46
- mod tags;
47
45
mod template;
48
46
mod value;
49
47
50
48
pub mod compiler;
49
+ pub mod filters;
51
50
pub mod interpreter;
51
+ pub mod tags;
52
52
53
53
pub use error:: Error ;
54
54
pub use parser:: { Parser , ParserBuilder } ;
Original file line number Diff line number Diff line change @@ -237,11 +237,21 @@ mod friendly_date {
237
237
}
238
238
239
239
fn parse_date ( s : & str ) -> Option < Date > {
240
- let formats = [ "%d %B %Y %H:%M:%S %z" , "%Y-%m-%d %H:%M:%S %z" ] ;
241
- formats
242
- . iter ( )
243
- . filter_map ( |f| Date :: parse_from_str ( s, f) . ok ( ) )
244
- . next ( )
240
+ match s {
241
+ "now" | "today" => {
242
+ let now = chrono:: offset:: Utc :: now ( ) ;
243
+ let now = now. naive_utc ( ) ;
244
+ let now = chrono:: DateTime :: from_utc ( now, chrono:: offset:: FixedOffset :: east ( 0 ) ) ;
245
+ Some ( now)
246
+ }
247
+ _ => {
248
+ let formats = [ "%d %B %Y %H:%M:%S %z" , "%Y-%m-%d %H:%M:%S %z" ] ;
249
+ formats
250
+ . iter ( )
251
+ . filter_map ( |f| Date :: parse_from_str ( s, f) . ok ( ) )
252
+ . next ( )
253
+ }
254
+ }
245
255
}
246
256
247
257
#[ cfg( test) ]
@@ -457,4 +467,24 @@ mod test {
457
467
assert_eq ! ( empty, TRUE ) ;
458
468
assert ! ( empty. is_truthy( ) ) ;
459
469
}
470
+
471
+ #[ test]
472
+ fn parse_date_empty_is_bad ( ) {
473
+ assert ! ( parse_date( "" ) . is_none( ) ) ;
474
+ }
475
+
476
+ #[ test]
477
+ fn parse_date_bad ( ) {
478
+ assert ! ( parse_date( "aaaaa" ) . is_none( ) ) ;
479
+ }
480
+
481
+ #[ test]
482
+ fn parse_date_now ( ) {
483
+ assert ! ( parse_date( "now" ) . is_some( ) ) ;
484
+ }
485
+
486
+ #[ test]
487
+ fn parse_date_today ( ) {
488
+ assert ! ( parse_date( "today" ) . is_some( ) ) ;
489
+ }
460
490
}
You can’t perform that action at this time.
0 commit comments