mirror of
https://github.com/vlang/v.git
synced 2025-09-08 06:41:58 -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))
|
sb.write_string(ordinal_suffix(t.month))
|
||||||
}
|
}
|
||||||
'MMM' {
|
'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' {
|
'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' {
|
'D' {
|
||||||
sb.write_string(t.day.str())
|
sb.write_string(t.day.str())
|
||||||
|
@ -476,3 +476,9 @@ fn test_parse_weekday() {
|
|||||||
tm_s := tm.custom_format(format)
|
tm_s := tm.custom_format(format)
|
||||||
assert tm_s == 'Thursday Jan 01 00:00:00 1970'
|
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