1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: use UTC time in Time.format_rfc3339, make test more robust

This commit is contained in:
Delyan Angelov 2022-12-11 10:36:29 +02:00
parent 2ecb892985
commit 94098eef79
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 7 additions and 2 deletions

View File

@ -24,7 +24,8 @@ pub fn (t Time) format_ss_milli() string {
// RFC3339 is an Internet profile, based on the ISO 8601 standard for for representation of dates and times using the Gregorian calendar. // RFC3339 is an Internet profile, based on the ISO 8601 standard for for representation of dates and times using the Gregorian calendar.
// It is intended to improve consistency and interoperability, when representing and using date and time in Internet protocols. // It is intended to improve consistency and interoperability, when representing and using date and time in Internet protocols.
pub fn (t Time) format_rfc3339() string { pub fn (t Time) format_rfc3339() string {
return '${t.year:04d}-${t.month:02d}-${t.day:02d}T${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${(t.microsecond / 1000):03d}Z' u := t.add(-offset() * second)
return '${u.year:04d}-${u.month:02d}-${u.day:02d}T${u.hour:02d}:${u.minute:02d}:${u.second:02d}.${(u.microsecond / 1000):03d}Z'
} }
// 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).

View File

@ -94,7 +94,11 @@ fn test_format_ss_milli() {
} }
fn test_format_rfc3339() { fn test_format_rfc3339() {
assert '1980-07-11T21:23:42.123Z' == time_to_test.format_rfc3339() // assert '1980-07-11T19:23:42.123Z'
res := time_to_test.format_rfc3339()
assert res.ends_with('23:42.123Z')
assert res.starts_with('1980-07-1')
assert res.contains('T')
} }
fn test_format_ss_micro() { fn test_format_ss_micro() {