]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar.ranges: support duration ``to`` argument
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 10 May 2023 17:36:15 +0000 (10:36 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 10 May 2023 17:36:15 +0000 (10:36 -0700)
extra/calendar/ranges/ranges-tests.factor
extra/calendar/ranges/ranges.factor

index 71de175d5c5d61718e723538ab57698c295a7215..a6f60163a5e49e96dddaa6c19bbf32181d1d9c6f 100644 (file)
@@ -12,7 +12,6 @@ USING: arrays calendar calendar.ranges kernel tools.test ;
     =
 ] unit-test
 
-
 ! forwards
 {
     {
@@ -47,3 +46,15 @@ USING: arrays calendar calendar.ranges kernel tools.test ;
     -1 days <timestamp-range> >array
 ] unit-test
 
+! duration to
+{
+    {
+        T{ timestamp { year 2023 } { month 6 } { day 21 } }
+        T{ timestamp { year 2023 } { month 6 } { day 24 } }
+        T{ timestamp { year 2023 } { month 6 } { day 27 } }
+        T{ timestamp { year 2023 } { month 6 } { day 30 } }
+    }
+} [
+    2023 06 21 <date-utc> 10 days
+    3 days <timestamp-range> >array
+] unit-test
index 042cba91be0677aa8a7ffea244df3947feb7096a..73b3860e16fd3f01fd75be0f94ab55559b16221e 100644 (file)
@@ -12,7 +12,7 @@ TUPLE: timestamp-range
     { step duration read-only } ;
 
 : <timestamp-range> ( from to step -- timestamp-range )
-    [ over time- ] dip [
+    [ dup duration? [ over time+ ] when over time- ] dip [
         [ duration>seconds ] bi@ sign/mod 0 < [ 1 + ] unless 0 max
     ] keep timestamp-range boa ;