mirror of
https://github.com/vlang/v.git
synced 2025-09-15 02:18:47 -04:00
time: add MMM
support for parse_format() (#19284)
This commit is contained in:
parent
3739175fdb
commit
c790afabdc
@ -88,6 +88,19 @@ fn (mut p DateTimeParser) must_be_valid_month() !int {
|
||||
return error_invalid_time(0, 'invalid month name')
|
||||
}
|
||||
|
||||
fn (mut p DateTimeParser) must_be_valid_three_letter_month() !int {
|
||||
for month_number := 1; month_number < long_months.len; month_number++ {
|
||||
if p.current_pos_datetime + 3 < p.datetime.len {
|
||||
month_three_letters := p.datetime[p.current_pos_datetime..p.current_pos_datetime + 3]
|
||||
if months_string[(month_number - 1) * 3..month_number * 3] == month_three_letters {
|
||||
p.current_pos_datetime += 3
|
||||
return month_number
|
||||
}
|
||||
}
|
||||
}
|
||||
return error_invalid_time(0, 'invalid month three letters')
|
||||
}
|
||||
|
||||
fn (mut p DateTimeParser) must_be_valid_week_day(letters int) !string {
|
||||
val := p.next(letters)!
|
||||
for v in long_days {
|
||||
@ -171,6 +184,9 @@ fn (mut p DateTimeParser) parse() !Time {
|
||||
return error_invalid_time(0, 'month must be between 01 and 12')
|
||||
}
|
||||
}
|
||||
'MMM' {
|
||||
month_ = p.must_be_valid_three_letter_month() or { return err }
|
||||
}
|
||||
'MMMM' {
|
||||
month_ = p.must_be_valid_month() or { return err }
|
||||
}
|
||||
|
@ -336,3 +336,11 @@ fn test_plus_equals_duration() {
|
||||
d += time.second
|
||||
assert d == 2 * time.second
|
||||
}
|
||||
|
||||
fn test_parse_three_letters_month() {
|
||||
tm := time.now()
|
||||
format := 'MMM DD HH:mm:ss YYYY'
|
||||
tm_s := tm.custom_format(format)
|
||||
tm_tm := time.parse_format(tm_s, format)!
|
||||
assert tm_tm.month == tm.month
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user