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

time: fix timezone

This commit is contained in:
vitalyster 2020-02-04 14:17:04 +03:00 committed by GitHub
parent 85e4e4cb40
commit 21b54723e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 8 deletions

View File

@ -252,7 +252,7 @@ pub fn (t &Time) calc_unix() int {
tm_mon: t.month - 1 tm_mon: t.month - 1
tm_year: t.year - 1900 tm_year: t.year - 1900
} }
return C.mktime(&tt) return make_unix_time(tt)
} }
// TODO add(d time.Duration) // TODO add(d time.Duration)

View File

@ -21,9 +21,11 @@ pub fn convert_ctime(t tm) Time {
hour: t.tm_hour hour: t.tm_hour
minute: t.tm_min minute: t.tm_min
second: t.tm_sec second: t.tm_sec
unix: C.mktime(&t) unix: make_unix_time(t)
}.add_seconds(t.tm_gmtoff) }
} }
[inline]
fn make_unix_time(t tm) int {
return C.mktime(&t) + t.tm_gmtoff
}

View File

@ -179,6 +179,7 @@ fn test_add_days() {
num_of_days := 3 num_of_days := 3
t := time_to_test.add_days(num_of_days) t := time_to_test.add_days(num_of_days)
assert t.day == time_to_test.day + num_of_days assert t.day == time_to_test.day + num_of_days
assert t.unix == time_to_test.unix + 86400 * num_of_days
} }
fn test_get_fmt_time_str() { fn test_get_fmt_time_str() {

View File

@ -10,7 +10,6 @@ struct C.tm {
tm_hour int tm_hour int
tm_min int tm_min int
tm_sec int tm_sec int
//tm_gmtoff int // seconds
} }
pub fn convert_ctime(t tm) Time { pub fn convert_ctime(t tm) Time {
@ -21,7 +20,11 @@ pub fn convert_ctime(t tm) Time {
hour: t.tm_hour hour: t.tm_hour
minute: t.tm_min minute: t.tm_min
second: t.tm_sec second: t.tm_sec
unix: C.mktime(&t) unix: make_unix_time(t)
}//.add_seconds(t.tm_gmtoff) }
} }
[inline]
fn make_unix_time(t tm) int {
return C.mktime(&t) - C._timezone
}