1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: fix parse_format with YY (#18887)

This commit is contained in:
Turiiya 2023-07-18 01:05:49 +02:00 committed by GitHub
parent 2eea59c4cc
commit bf98f7c9ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -163,7 +163,7 @@ fn (mut p DateTimeParser) parse() !Time {
}
}
'YY' {
year_ = p.must_be_int(2) or {
year_ = now().year / 100 * 100 + p.must_be_int(2) or {
return error_invalid_time(0, 'end of string reached before the full year was specified')
}
}

View File

@ -209,7 +209,6 @@ fn test_parse_format() {
assert false
return
}
assert t.year == 2018 && t.month == 1 && t.day == 27 && t.hour == 12 && t.minute == 48
&& t.second == 34
@ -222,8 +221,8 @@ fn test_parse_format() {
assert t.year == 2018 && t.month == 11 && t.day == 27 && t.hour == 12 && t.minute == 48
&& t.second == 20
s = '2018-1-2 1:8:2'
t = time.parse_format(s, 'YYYY-M-D H:m:s') or {
s = '18-1-2 1:8:2'
t = time.parse_format(s, 'YY-M-D H:m:s') or {
eprintln('> failing format: ${s} | err: ${err}')
assert false
return