aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/time/chrono.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/time/chrono.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/time/chrono.v')
-rw-r--r--v_windows/v/vlib/time/chrono.v14
1 files changed, 14 insertions, 0 deletions
diff --git a/v_windows/v/vlib/time/chrono.v b/v_windows/v/vlib/time/chrono.v
new file mode 100644
index 0000000..58f1ef8
--- /dev/null
+++ b/v_windows/v/vlib/time/chrono.v
@@ -0,0 +1,14 @@
+module time
+
+// days_from_civil - return the number of days since the
+// Unix epoch 1970-01-01. A detailed description of the algorithm here
+// is in: http://howardhinnant.github.io/date_algorithms.html
+// Note that it will return negative values for days before 1970-01-01.
+pub fn days_from_civil(oy int, m int, d int) int {
+ y := if m <= 2 { oy - 1 } else { oy }
+ era := y / 400
+ yoe := y - era * 400 // [0, 399]
+ doy := (153 * (m + (if m > 2 { -3 } else { 9 })) + 2) / 5 + d - 1 // [0, 365]
+ doe := yoe * 365 + yoe / 4 - yoe / 100 + doy // [0, 146096]
+ return era * 146097 + doe - 719468
+}