@@ -59,15 +59,15 @@ pub fn parse_relative_time_at_date<T: TimeZone>(
5959 return Ok ( datetime) ;
6060 }
6161 let time_pattern: Regex = Regex :: new (
62- r"(?x )
62+ r"(?ix )
6363 (?:(?P<value>[-+]?\s*\d*)\s*)?
6464 (\s*(?P<direction>next|this|last)?\s*)?
6565 (?P<unit>years?|months?|fortnights?|weeks?|days?|hours?|h|minutes?|mins?|m|seconds?|secs?|s|yesterday|tomorrow|now|today|(?P<weekday>[a-z]{3,9}))\b
6666 (\s*(?P<separator>and|,)?\s*)?
6767 (\s*(?P<ago>ago)?)?" ,
6868 ) ?;
6969
70- let mut is_ago = s. contains ( " ago" ) ;
70+ let mut is_ago = s. to_ascii_lowercase ( ) . contains ( " ago" ) ;
7171 let mut captures_processed = 0 ;
7272 let mut total_length = 0 ;
7373
@@ -81,7 +81,10 @@ pub fn parse_relative_time_at_date<T: TimeZone>(
8181 . chars ( )
8282 . filter ( |c| !c. is_whitespace ( ) ) // Remove potential space between +/- and number
8383 . collect ( ) ;
84- let direction = capture. name ( "direction" ) . map_or ( "" , |d| d. as_str ( ) ) ;
84+ let direction = capture
85+ . name ( "direction" )
86+ . map_or ( "" , |d| d. as_str ( ) )
87+ . to_ascii_lowercase ( ) ;
8588 let value = if value_str. is_empty ( ) {
8689 if direction == "this" {
8790 0
@@ -107,7 +110,7 @@ pub fn parse_relative_time_at_date<T: TimeZone>(
107110 is_ago = true ;
108111 }
109112
110- let new_datetime = match unit {
113+ let new_datetime = match unit. to_ascii_lowercase ( ) . as_str ( ) {
111114 "years" | "year" => add_months ( datetime, value * 12 , is_ago) ,
112115 "months" | "month" => add_months ( datetime, value, is_ago) ,
113116 "fortnights" | "fortnight" => add_days ( datetime, value * 14 , is_ago) ,
@@ -1021,4 +1024,16 @@ mod tests {
10211024 Err ( ParseDateTimeError :: InvalidInput )
10221025 ) ;
10231026 }
1027+
1028+ #[ test]
1029+ fn test_parse_relative_time_at_date_with_uppercase ( ) {
1030+ let tests = vec ! [ "today" , "last week" , "next month" , "1 year ago" ] ;
1031+ let now = Utc :: now ( ) ;
1032+ for t in tests {
1033+ assert_eq ! (
1034+ parse_relative_time_at_date( now, & t. to_uppercase( ) ) . unwrap( ) ,
1035+ parse_relative_time_at_date( now, t) . unwrap( ) ,
1036+ ) ;
1037+ }
1038+ }
10241039}
0 commit comments