@@ -59,15 +59,15 @@ pub fn parse_relative_time_at_date<T: TimeZone>(
59
59
return Ok ( datetime) ;
60
60
}
61
61
let time_pattern: Regex = Regex :: new (
62
- r"(?x )
62
+ r"(?ix )
63
63
(?:(?P<value>[-+]?\s*\d*)\s*)?
64
64
(\s*(?P<direction>next|this|last)?\s*)?
65
65
(?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
66
66
(\s*(?P<separator>and|,)?\s*)?
67
67
(\s*(?P<ago>ago)?)?" ,
68
68
) ?;
69
69
70
- let mut is_ago = s. contains ( " ago" ) ;
70
+ let mut is_ago = s. to_ascii_lowercase ( ) . contains ( " ago" ) ;
71
71
let mut captures_processed = 0 ;
72
72
let mut total_length = 0 ;
73
73
@@ -81,7 +81,10 @@ pub fn parse_relative_time_at_date<T: TimeZone>(
81
81
. chars ( )
82
82
. filter ( |c| !c. is_whitespace ( ) ) // Remove potential space between +/- and number
83
83
. 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 ( ) ;
85
88
let value = if value_str. is_empty ( ) {
86
89
if direction == "this" {
87
90
0
@@ -107,7 +110,7 @@ pub fn parse_relative_time_at_date<T: TimeZone>(
107
110
is_ago = true ;
108
111
}
109
112
110
- let new_datetime = match unit {
113
+ let new_datetime = match unit. to_ascii_lowercase ( ) . as_str ( ) {
111
114
"years" | "year" => add_months ( datetime, value * 12 , is_ago) ,
112
115
"months" | "month" => add_months ( datetime, value, is_ago) ,
113
116
"fortnights" | "fortnight" => add_days ( datetime, value * 14 , is_ago) ,
@@ -1021,4 +1024,16 @@ mod tests {
1021
1024
Err ( ParseDateTimeError :: InvalidInput )
1022
1025
) ;
1023
1026
}
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
+ }
1024
1039
}
0 commit comments