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:
parent
8a0cca2255
commit
4f629cd883
@ -58,18 +58,6 @@ fn (mut p DateTimeParser) must_be_int_with_minimum_length(min int, max int, allo
|
|||||||
return val.int()
|
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) ! {
|
fn (mut p DateTimeParser) must_be_string(must string) ! {
|
||||||
val := p.next(must.len)!
|
val := p.next(must.len)!
|
||||||
if val != must {
|
if val != must {
|
||||||
@ -203,7 +191,7 @@ fn (mut p DateTimeParser) parse() !Time {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
'H' {
|
'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')
|
return error_invalid_time(0, 'end of string reached before hours where specified')
|
||||||
}
|
}
|
||||||
if hour_ < 0 || hour_ > 23 {
|
if hour_ < 0 || hour_ > 23 {
|
||||||
@ -219,7 +207,7 @@ fn (mut p DateTimeParser) parse() !Time {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
'h' {
|
'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')
|
return error_invalid_time(0, 'end of string reached before hours where specified')
|
||||||
}
|
}
|
||||||
if hour_ < 0 || hour_ > 23 {
|
if hour_ < 0 || hour_ > 23 {
|
||||||
|
@ -221,13 +221,13 @@ fn test_parse_format() {
|
|||||||
assert t.year == 2018 && t.month == 11 && t.day == 27 && t.hour == 12 && t.minute == 48
|
assert t.year == 2018 && t.month == 11 && t.day == 27 && t.hour == 12 && t.minute == 48
|
||||||
&& t.second == 20
|
&& 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 {
|
t = time.parse_format(s, 'YY-M-D H:m:s') or {
|
||||||
eprintln('> failing format: ${s} | err: ${err}')
|
eprintln('> failing format: ${s} | err: ${err}')
|
||||||
assert false
|
assert false
|
||||||
return
|
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
|
&& t.second == 2
|
||||||
|
|
||||||
// This should always fail, because we test if M and D allow for a 01 value which they shouldn't
|
// This should always fail, because we test if M and D allow for a 01 value which they shouldn't
|
||||||
|
Loading…
x
Reference in New Issue
Block a user