mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04:00
parent
f719c2cbe3
commit
dc2a7b2b7c
@ -401,10 +401,20 @@ pub fn (t Time) custom_format(s string) string {
|
||||
sb.write_string(ordinal_suffix(t.month))
|
||||
}
|
||||
'MMM' {
|
||||
sb.write_string(long_months[t.month - 1][0..3])
|
||||
m := if t.month >= 1 && t.month <= 12 {
|
||||
long_months[t.month - 1][0..3]
|
||||
} else {
|
||||
long_months[0][0..3]
|
||||
}
|
||||
sb.write_string(m)
|
||||
}
|
||||
'MMMM' {
|
||||
sb.write_string(long_months[t.month - 1])
|
||||
m := if t.month >= 1 && t.month <= 12 {
|
||||
long_months[t.month - 1]
|
||||
} else {
|
||||
long_months[0]
|
||||
}
|
||||
sb.write_string(m)
|
||||
}
|
||||
'D' {
|
||||
sb.write_string(t.day.str())
|
||||
|
@ -476,3 +476,9 @@ fn test_parse_weekday() {
|
||||
tm_s := tm.custom_format(format)
|
||||
assert tm_s == 'Thursday Jan 01 00:00:00 1970'
|
||||
}
|
||||
|
||||
fn test_empty_time() {
|
||||
t := time.Time{}
|
||||
assert t.unix() == -62169984000
|
||||
assert t.custom_format('MMMM YYYY') == 'January 0'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user