From 696312902092bf06c6aa5b2d369d4348232be942 Mon Sep 17 00:00:00 2001 From: Henry Widd Date: Thu, 7 Sep 2023 11:59:18 +0100 Subject: [PATCH] duration function works on interval with LocalDate bounds --- src/tick/core.cljc | 4 ++-- test/tick/api_test.cljc | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tick/core.cljc b/src/tick/core.cljc index 4f5c461..d60d490 100644 --- a/src/tick/core.cljc +++ b/src/tick/core.cljc @@ -962,8 +962,8 @@ (defn beginning "the beginning of the range of ITimeSpan v or v" [v] (p/beginning v)) (defn end "the end of the range of ITimeSpan v or v" [v] (p/end v)) -(defn duration "return duration contained within the range of ITimeSpan 'x', which can be a year, year-month or date " [x] - (cljc.java-time.duration/between (beginning x) (end x))) +(defn duration "return Duration or Period (whichever appropriate based on type) contained within the range of ITimeSpan x" [x] + (between (beginning x) (end x))) ;; Periods diff --git a/test/tick/api_test.cljc b/test/tick/api_test.cljc index e2705cb..76c2780 100644 --- a/test/tick/api_test.cljc +++ b/test/tick/api_test.cljc @@ -434,7 +434,9 @@ (is (= (t/new-duration 1e9 :nanos) (t/new-duration 1 :seconds))) (is (= (t/new-duration 1000 :millis) (t/new-duration 1 :seconds))) - (is (= (t/new-duration 24 :hours) (t/duration (t/tomorrow))))) + (is (= (t/of-hours 24) (t/duration (t/date)))) + (is (= (t/of-days 1) (t/duration {:tick/beginning (t/date) + :tick/end (t/inc (t/date))})))) ;; Durations. Convenience functions to create durations of specific ;; units.