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:
parent
85e4e4cb40
commit
21b54723e4
@ -252,7 +252,7 @@ pub fn (t &Time) calc_unix() int {
|
||||
tm_mon: t.month - 1
|
||||
tm_year: t.year - 1900
|
||||
}
|
||||
return C.mktime(&tt)
|
||||
return make_unix_time(tt)
|
||||
}
|
||||
|
||||
// TODO add(d time.Duration)
|
||||
|
@ -21,9 +21,11 @@ pub fn convert_ctime(t tm) Time {
|
||||
hour: t.tm_hour
|
||||
minute: t.tm_min
|
||||
second: t.tm_sec
|
||||
unix: C.mktime(&t)
|
||||
}.add_seconds(t.tm_gmtoff)
|
||||
unix: make_unix_time(t)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[inline]
|
||||
fn make_unix_time(t tm) int {
|
||||
return C.mktime(&t) + t.tm_gmtoff
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ fn test_add_days() {
|
||||
num_of_days := 3
|
||||
t := time_to_test.add_days(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() {
|
||||
|
@ -10,7 +10,6 @@ struct C.tm {
|
||||
tm_hour int
|
||||
tm_min int
|
||||
tm_sec int
|
||||
//tm_gmtoff int // seconds
|
||||
}
|
||||
|
||||
pub fn convert_ctime(t tm) Time {
|
||||
@ -21,7 +20,11 @@ pub fn convert_ctime(t tm) Time {
|
||||
hour: t.tm_hour
|
||||
minute: t.tm_min
|
||||
second: t.tm_sec
|
||||
unix: C.mktime(&t)
|
||||
}//.add_seconds(t.tm_gmtoff)
|
||||
unix: make_unix_time(t)
|
||||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn make_unix_time(t tm) int {
|
||||
return C.mktime(&t) - C._timezone
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user