Skip to content

Commit

Permalink
time: fix parse_format with YY (#18887)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jul 17, 2023
1 parent 2eea59c commit bf98f7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vlib/time/date_time_parser.v
Expand Up @@ -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')
}
}
Expand Down
5 changes: 2 additions & 3 deletions vlib/time/parse_test.v
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit bf98f7c

Please sign in to comment.