aboutsummaryrefslogtreecommitdiff
path: root/core/time
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-09-03 00:40:51 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-09-03 00:55:09 -0400
commitf6f2c67f3755028d84b331f6e96ac4c4963dc78b (patch)
tree640b1c830f491953b37bc54b20349ac4f3a10fd4 /core/time
parent71b2527df07a8628093792bbf2a7886bed253a09 (diff)
Add `time.time_to_datetime`
Diffstat (limited to 'core/time')
-rw-r--r--core/time/time.odin18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/time/time.odin b/core/time/time.odin
index 5903b212d..98639b36a 100644
--- a/core/time/time.odin
+++ b/core/time/time.odin
@@ -955,6 +955,24 @@ Convert datetime components into time.
datetime_to_time :: proc{components_to_time, compound_to_time}
/*
+Convert time into datetime.
+*/
+time_to_datetime :: proc "contextless" (t: Time) -> (dt.DateTime, bool) {
+ unix_epoch := dt.DateTime{{1970, 1, 1}, {0, 0, 0, 0}}
+
+ datetime, err := dt.add(unix_epoch, dt.Delta{ nanos = t._nsec })
+ if err != .None {
+ return {}, false
+ }
+ return datetime, true
+}
+
+/*
+Alias for `time_to_datetime`.
+*/
+time_to_compound :: time_to_datetime
+
+/*
Check if a year is a leap year.
*/
is_leap_year :: proc "contextless" (year: int) -> (leap: bool) {