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

time: move C backend specific code into .c.v files (#11125)

This commit is contained in:
playX
2021-08-10 14:34:53 +03:00
committed by GitHub
parent 11794039e2
commit 8d6903a65a
5 changed files with 139 additions and 137 deletions

18
vlib/time/chrono.c.v Normal file
View File

@@ -0,0 +1,18 @@
module time
// portable_timegm does the same as C._mkgmtime, but unlike it,
// can work with dates before the Unix epoch of 1970-01-01 .
pub fn portable_timegm(t &C.tm) i64 {
mut year := t.tm_year + 1900
mut month := t.tm_mon // 0-11
if month > 11 {
year += month / 12
month %= 12
} else if month < 0 {
years_diff := (11 - month) / 12
year -= years_diff
month += 12 * years_diff
}
days_since_1970 := i64(days_from_civil(year, month + 1, t.tm_mday))
return 60 * (60 * (24 * days_since_1970 + t.tm_hour) + t.tm_min) + t.tm_sec
}