File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,19 @@ fn (mut p DateTimeParser) must_be_valid_month() !int {
88
88
return error_invalid_time (0 , 'invalid month name' )
89
89
}
90
90
91
+ fn (mut p DateTimeParser) must_be_valid_three_letter_month () ! int {
92
+ for month_number := 1 ; month_number < long_months.len; month_number++ {
93
+ if p.current_pos_datetime + 3 < p.datetime.len {
94
+ month_three_letters := p.datetime[p.current_pos_datetime..p.current_pos_datetime + 3 ]
95
+ if months_string[(month_number - 1 ) * 3 ..month_number * 3 ] == month_three_letters {
96
+ p.current_pos_datetime + = 3
97
+ return month_number
98
+ }
99
+ }
100
+ }
101
+ return error_invalid_time (0 , 'invalid month three letters' )
102
+ }
103
+
91
104
fn (mut p DateTimeParser) must_be_valid_week_day (letters int ) ! string {
92
105
val := p.next (letters)!
93
106
for v in long_days {
@@ -171,6 +184,9 @@ fn (mut p DateTimeParser) parse() !Time {
171
184
return error_invalid_time (0 , 'month must be between 01 and 12' )
172
185
}
173
186
}
187
+ 'MMM' {
188
+ month_ = p.must_be_valid_three_letter_month () or { return err }
189
+ }
174
190
'MMMM' {
175
191
month_ = p.must_be_valid_month () or { return err }
176
192
}
Original file line number Diff line number Diff line change @@ -336,3 +336,11 @@ fn test_plus_equals_duration() {
336
336
d + = time.second
337
337
assert d == 2 * time.second
338
338
}
339
+
340
+ fn test_parse_three_letters_month () {
341
+ tm := time.now ()
342
+ format := 'MMM DD HH:mm:ss YYYY'
343
+ tm_s := tm.custom_format (format)
344
+ tm_tm := time.parse_format (tm_s, format)!
345
+ assert tm_tm.month == tm.month
346
+ }
You can’t perform that action at this time.
0 commit comments