minimal.org 1.6 KB

(import (srfi srfi-19))

(define SECOND 1) (define MINUTE (* 60 SECOND)) (define HOUR (* 60 MINUTE))

(define org-timestamp-format "[~Y-~m-~d ~a ~H:~M]")

(define duration->time-utc (λ (duration) (make-time time-utc (time-nanosecond duration) (time-second duration))))

(define org-timestamp->time-utc (λ (timestamp-string) (let ([parsed-date (string->date timestamp-string org-timestamp-format)]) (date->time-utc parsed-date))))

(define org-time-duration (λ (org-timestamp-1 org-timestamp-2) (time-difference (org-timestamp->time-utc org-timestamp-2) (org-timestamp->time-utc org-timestamp-1))))

(define duration->org-timestamp (λ (duration) (time-utc->date (duration->time-utc duration) ;; timezone offset, assume all with no offset 0)))

(define duration->hours (λ (duration) (/ (time-second duration) HOUR)))

(number->string (duration->hours (org-time-duration org-timestamp-1 org-timestamp-2)))

timestamp 1 timestamp 2 result
# [2021-03-14 Sun 03:50] [2021-03-14 Sun 03:55]
# [2021-03-14 Sun 03:50] [2021-03-14 Sun 03:50] nil
# [2021-03-14 Sun 03:50] [2021-03-14 Sun 03:50]