aboutsummaryrefslogtreecommitdiff
path: root/module/datetime.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-04-05 23:36:42 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-04-05 23:36:42 +0200
commit8e527c8b5d9f41fb1ef8fbd98396d57635ac4314 (patch)
tree09e2ae60f79b650b39883227c9bbf9575e04c9e6 /module/datetime.scm
parentCSS made smallcal links larger. (diff)
downloadcalp-8e527c8b5d9f41fb1ef8fbd98396d57635ac4314.tar.gz
calp-8e527c8b5d9f41fb1ef8fbd98396d57635ac4314.tar.xz
Introduce datetime->unix-time and back.
Diffstat (limited to 'module/datetime.scm')
-rw-r--r--module/datetime.scm10
1 files changed, 10 insertions, 0 deletions
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