File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -627,10 +627,14 @@ pub fn date(input: &Value, args: &[Value]) -> FilterResult {
627
627
let input_string = input
628
628
. as_str ( )
629
629
. ok_or_else ( || FilterError :: InvalidType ( " expected" . to_owned ( ) ) ) ?;
630
- let date = DateTime :: parse_from_str ( input_string, "%d %B %Y %H:%M:%S %z" ) ;
630
+ let formats = [ "%d %B %Y %H:%M:%S %z" , "%Y-%m-%d %H:%M:%S %z" ] ;
631
+ let date = formats
632
+ . iter ( )
633
+ . filter_map ( |f| DateTime :: parse_from_str ( input_string, f) . ok ( ) )
634
+ . next ( ) ;
631
635
let date = match date {
632
- Ok ( d) => d,
633
- Err ( _ ) => {
636
+ Some ( d) => d,
637
+ None => {
634
638
return Ok ( input. clone ( ) ) ;
635
639
}
636
640
} ;
@@ -1025,6 +1029,12 @@ mod tests {
1025
1029
tos!( "2016-06-13" ) ) ;
1026
1030
}
1027
1031
1032
+ #[ test]
1033
+ fn unit_date_cobalt_format ( ) {
1034
+ assert_eq ! ( unit!( date, tos!( "2016-06-13 02:30:00 +0300" ) , & [ tos!( "%Y-%m-%d" ) ] ) ,
1035
+ tos!( "2016-06-13" ) ) ;
1036
+ }
1037
+
1028
1038
#[ test]
1029
1039
fn unit_date_bad_input_type ( ) {
1030
1040
assert_eq ! ( failed!( date, Value :: Num ( 0f32 ) , & [ tos!( "%Y-%m-%d" ) ] ) ,
You can’t perform that action at this time.
0 commit comments