time: do not panic on time.new_time({unix: 1608854400}).str()
parent
96b7cce810
commit
e2e683199d
|
@ -118,16 +118,16 @@ pub fn (t Time) get_fmt_date_str(fmt_dlmtr FormatDelimiter, fmt_date FormatDate)
|
|||
return ''
|
||||
}
|
||||
month := '$t.smonth()'
|
||||
year := t.year.str()[2..]
|
||||
year := '${(t.year % 100):02d}'
|
||||
mut res := match fmt_date {
|
||||
.ddmmyy { '${t.day:02d}|${t.month:02d}|$year' }
|
||||
.ddmmyyyy { '${t.day:02d}|${t.month:02d}|$t.year' }
|
||||
.ddmmyyyy { '${t.day:02d}|${t.month:02d}|${t.year:04d}' }
|
||||
.mmddyy { '${t.month:02d}|${t.day:02d}|$year' }
|
||||
.mmddyyyy { '${t.month:02d}|${t.day:02d}|$t.year' }
|
||||
.mmddyyyy { '${t.month:02d}|${t.day:02d}|${t.year:04d}' }
|
||||
.mmmd { '$month|$t.day' }
|
||||
.mmmdd { '$month|${t.day:02d}' }
|
||||
.mmmddyyyy { '$month|${t.day:02d}|$t.year' }
|
||||
.yyyymmdd { '$t.year|${t.month:02d}|${t.day:02d}' }
|
||||
.mmmddyyyy { '$month|${t.day:02d}|${t.year:04d}' }
|
||||
.yyyymmdd { '${t.year:04d}|${t.month:02d}|${t.day:02d}' }
|
||||
else { 'unknown enumeration $fmt_date' }
|
||||
}
|
||||
del := match fmt_dlmtr {
|
||||
|
|
|
@ -133,6 +133,9 @@ pub fn utc() Time {
|
|||
|
||||
// smonth returns month name.
|
||||
pub fn (t Time) smonth() string {
|
||||
if t.month <= 0 || t.month > 12 {
|
||||
return '---'
|
||||
}
|
||||
i := t.month - 1
|
||||
return months_string[i * 3..(i + 1) * 3]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue