time: simplify some very commonly used t.format methods

master
Delyan Angelov 2022-05-22 21:09:49 +03:00
parent e5ff2ab455
commit 5328dabad1
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 6 deletions

View File

@ -7,32 +7,32 @@ import strings
// format returns a date string in "YYYY-MM-DD HH:mm" format (24h). // format returns a date string in "YYYY-MM-DD HH:mm" format (24h).
pub fn (t Time) format() string { pub fn (t Time) format() string {
return t.get_fmt_str(.hyphen, .hhmm24, .yyyymmdd) return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}'
} }
// format_ss returns a date string in "YYYY-MM-DD HH:mm:ss" format (24h). // format_ss returns a date string in "YYYY-MM-DD HH:mm:ss" format (24h).
pub fn (t Time) format_ss() string { pub fn (t Time) format_ss() string {
return t.get_fmt_str(.hyphen, .hhmmss24, .yyyymmdd) return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}'
} }
// format_ss_milli returns a date string in "YYYY-MM-DD HH:mm:ss.123" format (24h). // format_ss_milli returns a date string in "YYYY-MM-DD HH:mm:ss.123" format (24h).
pub fn (t Time) format_ss_milli() string { pub fn (t Time) format_ss_milli() string {
return t.get_fmt_str(.hyphen, .hhmmss24_milli, .yyyymmdd) return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${(t.microsecond / 1000):03d}'
} }
// format_ss_micro returns a date string in "YYYY-MM-DD HH:mm:ss.123456" format (24h). // format_ss_micro returns a date string in "YYYY-MM-DD HH:mm:ss.123456" format (24h).
pub fn (t Time) format_ss_micro() string { pub fn (t Time) format_ss_micro() string {
return t.get_fmt_str(.hyphen, .hhmmss24_micro, .yyyymmdd) return '${t.year:04d}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${t.microsecond:06d}'
} }
// hhmm returns a date string in "HH:mm" format (24h). // hhmm returns a date string in "HH:mm" format (24h).
pub fn (t Time) hhmm() string { pub fn (t Time) hhmm() string {
return t.get_fmt_time_str(.hhmm24) return '${t.hour:02d}:${t.minute:02d}'
} }
// hhmmss returns a date string in "HH:mm:ss" format (24h). // hhmmss returns a date string in "HH:mm:ss" format (24h).
pub fn (t Time) hhmmss() string { pub fn (t Time) hhmmss() string {
return t.get_fmt_time_str(.hhmmss24) return '${t.hour:02d}:${t.minute:02d}:${t.second:02d}'
} }
// hhmm12 returns a date string in "hh:mm" format (12h). // hhmm12 returns a date string in "hh:mm" format (12h).