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

time: fix hour 0 parsing, remove unused function (#18897)

This commit is contained in:
Turiiya 2023-07-18 16:28:40 +02:00 committed by GitHub
parent 8a0cca2255
commit 4f629cd883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 16 deletions

View File

@ -58,18 +58,6 @@ fn (mut p DateTimeParser) must_be_int_with_minimum_length(min int, max int, allo
return val.int()
}
fn (mut p DateTimeParser) must_be_single_int_with_optional_leading_zero() !int {
mut val := p.next(1)!
if val == '0' {
next := p.next(1) or { '' }
if !next.contains_only('0123456789') {
return error('expected int, found: ${next}')
}
val += next
}
return val.int()
}
fn (mut p DateTimeParser) must_be_string(must string) ! {
val := p.next(must.len)!
if val != must {
@ -203,7 +191,7 @@ fn (mut p DateTimeParser) parse() !Time {
}
}
'H' {
hour_ = p.must_be_int_with_minimum_length(1, 2, false) or {
hour_ = p.must_be_int_with_minimum_length(1, 2, true) or {
return error_invalid_time(0, 'end of string reached before hours where specified')
}
if hour_ < 0 || hour_ > 23 {
@ -219,7 +207,7 @@ fn (mut p DateTimeParser) parse() !Time {
}
}
'h' {
hour_ = p.must_be_int_with_minimum_length(1, 2, false) or {
hour_ = p.must_be_int_with_minimum_length(1, 2, true) or {
return error_invalid_time(0, 'end of string reached before hours where specified')
}
if hour_ < 0 || hour_ > 23 {

View File

@ -221,13 +221,13 @@ fn test_parse_format() {
assert t.year == 2018 && t.month == 11 && t.day == 27 && t.hour == 12 && t.minute == 48
&& t.second == 20
s = '18-1-2 1:8:2'
s = '18-1-2 0:8:2'
t = time.parse_format(s, 'YY-M-D H:m:s') or {
eprintln('> failing format: ${s} | err: ${err}')
assert false
return
}
assert t.year == 2018 && t.month == 1 && t.day == 2 && t.hour == 1 && t.minute == 8
assert t.year == 2018 && t.month == 1 && t.day == 2 && t.hour == 0 && t.minute == 8
&& t.second == 2
// This should always fail, because we test if M and D allow for a 01 value which they shouldn't