mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: fix 'h'
, 'hh'
in custom_format
for 12pm (#19058)
This commit is contained in:
parent
301320f4b0
commit
e5cd1724f9
@ -9,3 +9,57 @@ fn test_custom_format() {
|
|||||||
|
|
||||||
println(date.custom_format(test_str))
|
println(date.custom_format(test_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_hh() {
|
||||||
|
assert time.parse('2023-08-04 00:00:45')!.custom_format('hh') == '00'
|
||||||
|
assert time.parse('2023-08-04 01:00:45')!.custom_format('hh') == '01'
|
||||||
|
assert time.parse('2023-08-04 02:00:45')!.custom_format('hh') == '02'
|
||||||
|
assert time.parse('2023-08-04 03:00:45')!.custom_format('hh') == '03'
|
||||||
|
assert time.parse('2023-08-04 04:00:45')!.custom_format('hh') == '04'
|
||||||
|
assert time.parse('2023-08-04 05:00:45')!.custom_format('hh') == '05'
|
||||||
|
assert time.parse('2023-08-04 06:00:45')!.custom_format('hh') == '06'
|
||||||
|
assert time.parse('2023-08-04 07:00:45')!.custom_format('hh') == '07'
|
||||||
|
assert time.parse('2023-08-04 08:00:45')!.custom_format('hh') == '08'
|
||||||
|
assert time.parse('2023-08-04 09:00:45')!.custom_format('hh') == '09'
|
||||||
|
assert time.parse('2023-08-04 10:00:45')!.custom_format('hh') == '10'
|
||||||
|
assert time.parse('2023-08-04 11:00:45')!.custom_format('hh') == '11'
|
||||||
|
assert time.parse('2023-08-04 12:00:45')!.custom_format('hh') == '12'
|
||||||
|
assert time.parse('2023-08-04 13:00:45')!.custom_format('hh') == '01'
|
||||||
|
assert time.parse('2023-08-04 14:00:45')!.custom_format('hh') == '02'
|
||||||
|
assert time.parse('2023-08-04 15:00:45')!.custom_format('hh') == '03'
|
||||||
|
assert time.parse('2023-08-04 16:00:45')!.custom_format('hh') == '04'
|
||||||
|
assert time.parse('2023-08-04 17:00:45')!.custom_format('hh') == '05'
|
||||||
|
assert time.parse('2023-08-04 18:00:45')!.custom_format('hh') == '06'
|
||||||
|
assert time.parse('2023-08-04 19:00:45')!.custom_format('hh') == '07'
|
||||||
|
assert time.parse('2023-08-04 20:00:45')!.custom_format('hh') == '08'
|
||||||
|
assert time.parse('2023-08-04 21:00:45')!.custom_format('hh') == '09'
|
||||||
|
assert time.parse('2023-08-04 22:00:45')!.custom_format('hh') == '10'
|
||||||
|
assert time.parse('2023-08-04 23:00:45')!.custom_format('hh') == '11'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_h() {
|
||||||
|
assert time.parse('2023-08-04 00:00:45')!.custom_format('h') == '0'
|
||||||
|
assert time.parse('2023-08-04 01:00:45')!.custom_format('h') == '1'
|
||||||
|
assert time.parse('2023-08-04 02:00:45')!.custom_format('h') == '2'
|
||||||
|
assert time.parse('2023-08-04 03:00:45')!.custom_format('h') == '3'
|
||||||
|
assert time.parse('2023-08-04 04:00:45')!.custom_format('h') == '4'
|
||||||
|
assert time.parse('2023-08-04 05:00:45')!.custom_format('h') == '5'
|
||||||
|
assert time.parse('2023-08-04 06:00:45')!.custom_format('h') == '6'
|
||||||
|
assert time.parse('2023-08-04 07:00:45')!.custom_format('h') == '7'
|
||||||
|
assert time.parse('2023-08-04 08:00:45')!.custom_format('h') == '8'
|
||||||
|
assert time.parse('2023-08-04 09:00:45')!.custom_format('h') == '9'
|
||||||
|
assert time.parse('2023-08-04 10:00:45')!.custom_format('h') == '10'
|
||||||
|
assert time.parse('2023-08-04 11:00:45')!.custom_format('h') == '11'
|
||||||
|
assert time.parse('2023-08-04 12:00:45')!.custom_format('h') == '12'
|
||||||
|
assert time.parse('2023-08-04 13:00:45')!.custom_format('h') == '1'
|
||||||
|
assert time.parse('2023-08-04 14:00:45')!.custom_format('h') == '2'
|
||||||
|
assert time.parse('2023-08-04 15:00:45')!.custom_format('h') == '3'
|
||||||
|
assert time.parse('2023-08-04 16:00:45')!.custom_format('h') == '4'
|
||||||
|
assert time.parse('2023-08-04 17:00:45')!.custom_format('h') == '5'
|
||||||
|
assert time.parse('2023-08-04 18:00:45')!.custom_format('h') == '6'
|
||||||
|
assert time.parse('2023-08-04 19:00:45')!.custom_format('h') == '7'
|
||||||
|
assert time.parse('2023-08-04 20:00:45')!.custom_format('h') == '8'
|
||||||
|
assert time.parse('2023-08-04 21:00:45')!.custom_format('h') == '9'
|
||||||
|
assert time.parse('2023-08-04 22:00:45')!.custom_format('h') == '10'
|
||||||
|
assert time.parse('2023-08-04 23:00:45')!.custom_format('h') == '11'
|
||||||
|
}
|
||||||
|
@ -221,10 +221,12 @@ pub fn (t Time) custom_format(s string) string {
|
|||||||
sb.write_string('${t.hour:02}')
|
sb.write_string('${t.hour:02}')
|
||||||
}
|
}
|
||||||
'h' {
|
'h' {
|
||||||
sb.write_string((t.hour % 12).str())
|
h := if t.hour > 12 { t.hour - 12 } else { t.hour }
|
||||||
|
sb.write_string(h.str())
|
||||||
}
|
}
|
||||||
'hh' {
|
'hh' {
|
||||||
sb.write_string('${(t.hour % 12):02}')
|
h := if t.hour > 12 { t.hour - 12 } else { t.hour }
|
||||||
|
sb.write_string('${h:02}')
|
||||||
}
|
}
|
||||||
'm' {
|
'm' {
|
||||||
sb.write_string(t.minute.str())
|
sb.write_string(t.minute.str())
|
||||||
|
Loading…
Reference in New Issue
Block a user