diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/time/chrono.c.v | |
download | cli-tools-windows-master.tar.gz cli-tools-windows-master.tar.bz2 cli-tools-windows-master.zip |
Diffstat (limited to 'v_windows/v/vlib/time/chrono.c.v')
-rw-r--r-- | v_windows/v/vlib/time/chrono.c.v | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/v_windows/v/vlib/time/chrono.c.v b/v_windows/v/vlib/time/chrono.c.v new file mode 100644 index 0000000..4d6de7d --- /dev/null +++ b/v_windows/v/vlib/time/chrono.c.v @@ -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 +} |