time: extend date str formats (#9543)

pull/9555/head
AAAA 2021-04-01 04:04:59 -06:00 committed by GitHub
parent 0d1714cb0d
commit 043f6420f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

View File

@ -126,8 +126,10 @@ pub fn (t Time) get_fmt_date_str(fmt_dlmtr FormatDelimiter, fmt_date FormatDate)
.mmddyyyy { '${t.month:02d}|${t.day:02d}|${t.year:04d}' }
.mmmd { '$month|$t.day' }
.mmmdd { '$month|${t.day:02d}' }
.mmmddyy { '$month|${t.day:02d}|$year' }
.mmmddyyyy { '$month|${t.day:02d}|${t.year:04d}' }
.yyyymmdd { '${t.year:04d}|${t.month:02d}|${t.day:02d}' }
.yymmdd { '$year|${t.month:02d}|${t.day:02d}' }
else { 'unknown enumeration $fmt_date' }
}
del := match fmt_dlmtr {

View File

@ -72,9 +72,11 @@ pub enum FormatDate {
mmddyyyy
mmmd
mmmdd
mmmddyy
mmmddyyyy
no_date
yyyymmdd
yymmdd
}
// FormatDelimiter contains different time/date delimiters.

View File

@ -72,8 +72,10 @@ fn test_get_fmt_date_str() {
assert '07 11 80' == time_to_test.get_fmt_date_str(.space, .mmddyy)
assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmd)
assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmdd)
assert 'Jul 11 80' == time_to_test.get_fmt_date_str(.space, .mmmddyy)
assert 'Jul 11 1980' == time_to_test.get_fmt_date_str(.space, .mmmddyyyy)
assert '1980-07-11' == time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd)
assert '80.07.11' == time_to_test.get_fmt_date_str(.dot, .yymmdd)
}
fn test_get_fmt_str() {