Skip to content

Commit bf98f7c

Browse files
authored
time: fix parse_format with YY (#18887)
1 parent 2eea59c commit bf98f7c

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

vlib/time/date_time_parser.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn (mut p DateTimeParser) parse() !Time {
163163
}
164164
}
165165
'YY' {
166-
year_ = p.must_be_int(2) or {
166+
year_ = now().year / 100 * 100 + p.must_be_int(2) or {
167167
return error_invalid_time(0, 'end of string reached before the full year was specified')
168168
}
169169
}

vlib/time/parse_test.v

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ fn test_parse_format() {
209209
assert false
210210
return
211211
}
212-
213212
assert t.year == 2018 && t.month == 1 && t.day == 27 && t.hour == 12 && t.minute == 48
214213
&& t.second == 34
215214

@@ -222,8 +221,8 @@ fn test_parse_format() {
222221
assert t.year == 2018 && t.month == 11 && t.day == 27 && t.hour == 12 && t.minute == 48
223222
&& t.second == 20
224223

225-
s = '2018-1-2 1:8:2'
226-
t = time.parse_format(s, 'YYYY-M-D H:m:s') or {
224+
s = '18-1-2 1:8:2'
225+
t = time.parse_format(s, 'YY-M-D H:m:s') or {
227226
eprintln('> failing format: ${s} | err: ${err}')
228227
assert false
229228
return

0 commit comments

Comments
 (0)