From bb2b57e7bfc8f649283737fc0e8b18320ab0b3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 8 Nov 2019 20:32:54 +0100 Subject: Fix leap-seconds in normalize-date*. --- module/srfi/srfi-19/util.scm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'module/srfi') diff --git a/module/srfi/srfi-19/util.scm b/module/srfi/srfi-19/util.scm index 4155b263..ff23dbb9 100644 --- a/module/srfi/srfi-19/util.scm +++ b/module/srfi/srfi-19/util.scm @@ -98,11 +98,21 @@ attribute set to 0. Can also be seen as \"Start of day\"" (timedate (date->time-utc date) (zone-offset date))) -(define-public normalize-date* - (compose time-utc->date date->time-utc)) +;; Normalize a date on a weird form back into a propper form, +;; for example, 2019-11-32 becomes 2019-12-02. +;; The whole adding 10 seconds and then removing them is a dirty +;; hack to handle leap seconds. NOTE this should be reworked. +(define-public (normalize-date* date) + (define next-date + (date-second + (time-utc->date + (add-duration (date->time-utc date) + (make-time time-duration 0 10))) + (set next-date 0)))) ;; Returns a stream of date objects, one day appart, staring from start-day. (define-public (day-stream start-day) -- cgit v1.2.3