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 {
627627 let input_string = input
628628 . as_str ( )
629629 . 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 ( ) ;
631635 let date = match date {
632- Ok ( d) => d,
633- Err ( _ ) => {
636+ Some ( d) => d,
637+ None => {
634638 return Ok ( input. clone ( ) ) ;
635639 }
636640 } ;
@@ -1025,6 +1029,12 @@ mod tests {
10251029 tos!( "2016-06-13" ) ) ;
10261030 }
10271031
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+
10281038 #[ test]
10291039 fn unit_date_bad_input_type ( ) {
10301040 assert_eq ! ( failed!( date, Value :: Num ( 0f32 ) , & [ tos!( "%Y-%m-%d" ) ] ) ,
You can’t perform that action at this time.
0 commit comments