mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: fix 'a'
and 'A'
in custom_format
(#19060)
This commit is contained in:
parent
da7a9bc8ae
commit
8e26ca3f5a
@ -10,56 +10,29 @@ fn test_custom_format() {
|
|||||||
println(date.custom_format(test_str))
|
println(date.custom_format(test_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_hh() {
|
fn test_hours() {
|
||||||
assert time.parse('2023-08-04 00:00:45')!.custom_format('hh') == '00'
|
assert time.parse('2023-08-04 00:00:45')!.custom_format('hh A h a') == '00 AM 0 am'
|
||||||
assert time.parse('2023-08-04 01:00:45')!.custom_format('hh') == '01'
|
assert time.parse('2023-08-04 01:00:45')!.custom_format('hh A h a') == '01 AM 1 am'
|
||||||
assert time.parse('2023-08-04 02:00:45')!.custom_format('hh') == '02'
|
assert time.parse('2023-08-04 02:00:45')!.custom_format('hh A h a') == '02 AM 2 am'
|
||||||
assert time.parse('2023-08-04 03:00:45')!.custom_format('hh') == '03'
|
assert time.parse('2023-08-04 03:00:45')!.custom_format('hh A h a') == '03 AM 3 am'
|
||||||
assert time.parse('2023-08-04 04:00:45')!.custom_format('hh') == '04'
|
assert time.parse('2023-08-04 04:00:45')!.custom_format('hh A h a') == '04 AM 4 am'
|
||||||
assert time.parse('2023-08-04 05:00:45')!.custom_format('hh') == '05'
|
assert time.parse('2023-08-04 05:00:45')!.custom_format('hh A h a') == '05 AM 5 am'
|
||||||
assert time.parse('2023-08-04 06:00:45')!.custom_format('hh') == '06'
|
assert time.parse('2023-08-04 06:00:45')!.custom_format('hh A h a') == '06 AM 6 am'
|
||||||
assert time.parse('2023-08-04 07:00:45')!.custom_format('hh') == '07'
|
assert time.parse('2023-08-04 07:00:45')!.custom_format('hh A h a') == '07 AM 7 am'
|
||||||
assert time.parse('2023-08-04 08:00:45')!.custom_format('hh') == '08'
|
assert time.parse('2023-08-04 08:00:45')!.custom_format('hh A h a') == '08 AM 8 am'
|
||||||
assert time.parse('2023-08-04 09:00:45')!.custom_format('hh') == '09'
|
assert time.parse('2023-08-04 09:00:45')!.custom_format('hh A h a') == '09 AM 9 am'
|
||||||
assert time.parse('2023-08-04 10:00:45')!.custom_format('hh') == '10'
|
assert time.parse('2023-08-04 10:00:45')!.custom_format('hh A h a') == '10 AM 10 am'
|
||||||
assert time.parse('2023-08-04 11:00:45')!.custom_format('hh') == '11'
|
assert time.parse('2023-08-04 11:00:45')!.custom_format('hh A h a') == '11 AM 11 am'
|
||||||
assert time.parse('2023-08-04 12:00:45')!.custom_format('hh') == '12'
|
assert time.parse('2023-08-04 12:00:45')!.custom_format('hh A h a') == '12 PM 12 pm'
|
||||||
assert time.parse('2023-08-04 13:00:45')!.custom_format('hh') == '01'
|
assert time.parse('2023-08-04 13:00:45')!.custom_format('hh A h a') == '01 PM 1 pm'
|
||||||
assert time.parse('2023-08-04 14:00:45')!.custom_format('hh') == '02'
|
assert time.parse('2023-08-04 14:00:45')!.custom_format('hh A h a') == '02 PM 2 pm'
|
||||||
assert time.parse('2023-08-04 15:00:45')!.custom_format('hh') == '03'
|
assert time.parse('2023-08-04 15:00:45')!.custom_format('hh A h a') == '03 PM 3 pm'
|
||||||
assert time.parse('2023-08-04 16:00:45')!.custom_format('hh') == '04'
|
assert time.parse('2023-08-04 16:00:45')!.custom_format('hh A h a') == '04 PM 4 pm'
|
||||||
assert time.parse('2023-08-04 17:00:45')!.custom_format('hh') == '05'
|
assert time.parse('2023-08-04 17:00:45')!.custom_format('hh A h a') == '05 PM 5 pm'
|
||||||
assert time.parse('2023-08-04 18:00:45')!.custom_format('hh') == '06'
|
assert time.parse('2023-08-04 18:00:45')!.custom_format('hh A h a') == '06 PM 6 pm'
|
||||||
assert time.parse('2023-08-04 19:00:45')!.custom_format('hh') == '07'
|
assert time.parse('2023-08-04 19:00:45')!.custom_format('hh A h a') == '07 PM 7 pm'
|
||||||
assert time.parse('2023-08-04 20:00:45')!.custom_format('hh') == '08'
|
assert time.parse('2023-08-04 20:00:45')!.custom_format('hh A h a') == '08 PM 8 pm'
|
||||||
assert time.parse('2023-08-04 21:00:45')!.custom_format('hh') == '09'
|
assert time.parse('2023-08-04 21:00:45')!.custom_format('hh A h a') == '09 PM 9 pm'
|
||||||
assert time.parse('2023-08-04 22:00:45')!.custom_format('hh') == '10'
|
assert time.parse('2023-08-04 22:00:45')!.custom_format('hh A h a') == '10 PM 10 pm'
|
||||||
assert time.parse('2023-08-04 23:00:45')!.custom_format('hh') == '11'
|
assert time.parse('2023-08-04 23:00:45')!.custom_format('hh A h a') == '11 PM 11 pm'
|
||||||
}
|
|
||||||
|
|
||||||
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'
|
|
||||||
}
|
}
|
||||||
|
@ -308,17 +308,17 @@ pub fn (t Time) custom_format(s string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
'a' {
|
'a' {
|
||||||
if t.hour > 12 {
|
if t.hour < 12 {
|
||||||
sb.write_string('pm')
|
|
||||||
} else {
|
|
||||||
sb.write_string('am')
|
sb.write_string('am')
|
||||||
|
} else {
|
||||||
|
sb.write_string('pm')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'A' {
|
'A' {
|
||||||
if t.hour > 12 {
|
if t.hour < 12 {
|
||||||
sb.write_string('PM')
|
|
||||||
} else {
|
|
||||||
sb.write_string('AM')
|
sb.write_string('AM')
|
||||||
|
} else {
|
||||||
|
sb.write_string('PM')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user