From 8e527c8b5d9f41fb1ef8fbd98396d57635ac4314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 5 Apr 2020 23:36:42 +0200 Subject: Introduce datetime->unix-time and back. --- module/datetime.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'module/datetime.scm') diff --git a/module/datetime.scm b/module/datetime.scm index 30fb6025..0b3179ee 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -98,6 +98,7 @@ ;; NOTE there isn't any stable way to craft the tm objects. ;; I could call mktime on some date, and replace the fields ;; with the set-tm:*, but that is worse that breaking the API. +;; TODO TZ! (define (datetime->tm datetime) (let ((t (get-time% datetime)) (d (get-date datetime))) @@ -113,6 +114,7 @@ #f ; TZ name ))) +;; TODO TZ (define (tm->datetime tm) (datetime year: (+ 1900 (tm:year tm)) month: (1+ (tm:mon tm)) @@ -121,6 +123,14 @@ minute: (tm:min tm) second: (tm:sec tm))) +(define-public (datetime->unix-time dt) + (car (mktime (datetime->tm dt)))) + +(define-public (unix-time->datetime n) + (tm->datetime (gmtime n))) + +;; TODO prodedure to change TZ for datetime object + ;; datetime → datetime ;; Takes a datetime in any timezone, and renormalize it to local time -- cgit v1.2.3