]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar: adding >local-time! and some docs.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 10 Dec 2020 23:40:45 +0000 (15:40 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 10 Dec 2020 23:40:45 +0000 (15:40 -0800)
basis/calendar/calendar-docs.factor
basis/calendar/calendar.factor

index b72f566293a4643cec5115554049882ff146b31a..ae3ce64c126cdbcd8ae635da446f71b39016c68b 100644 (file)
@@ -141,7 +141,7 @@ HELP: leap-year?
 } ;
 
 HELP: time+
-{ $values { "time1" "timestamp or duration" } { "time2" "timestamp or duration" } { "time3" "timestamp or duration" } }
+{ $values { "time1" { $or timestamp duration } } { "time2" { $or timestamp duration } } { "time3" { $or timestamp duration } } }
 { $description "Adds two durations to produce a duration or adds a timestamp and a duration to produce a timestamp. The calculation takes timezones into account." }
 { $examples
     { $example "USING: calendar math.order prettyprint ;"
@@ -246,7 +246,7 @@ HELP: duration>nanoseconds
 
 
 HELP: time-
-{ $values { "time1" "timestamp or duration" } { "time2" "timestamp or duration" } { "time3" "timestamp or duration" } }
+{ $values { "time1" { $or timestamp duration } } { "time2" { $or timestamp duration } } { "time3" { $or timestamp duration } } }
 { $description "Subtracts two durations to produce a duration or subtracts a duration from a timestamp to produce a timestamp. The calculation takes timezones into account." }
 { $examples
     { $example "USING: calendar math.order prettyprint ;"
@@ -279,6 +279,8 @@ HELP: >local-time
     }
 } ;
 
+{ >local-time >local-time! } related-words
+
 HELP: >gmt
 { $values { "timestamp" timestamp } { "timestamp'" timestamp } }
 { $description "Converts the " { $snippet "timestamp" } " to the GMT timezone." }
@@ -289,6 +291,8 @@ HELP: >gmt
     }
 } ;
 
+{ >gmt >gmt! } related-words
+
 HELP: time*
 { $values { "obj1" object } { "obj2" object } { "obj3" object } }
 { $description "Multiplies each time slot of a timestamp or duration by a number and make a new duration from the result. Used in the implementation of " { $link before } "." } ;
@@ -362,7 +366,7 @@ HELP: (day-of-week)
 { $notes "User code should use the " { $link day-of-week } " word, which takes a " { $snippet "timestamp" } " instead of integers." } ;
 
 HELP: days-in-year
-{ $values { "obj" "a timestamp or an integer" } { "n" integer } }
+{ $values { "obj" { $or timestamp integer } } { "n" integer } }
 { $description "Calculates the number of days in a given year." }
 { $examples
     { $example "USING: calendar prettyprint ;"
index b436345a2ea0eb9a171413d6fad2d4bf4004406b..b0db381ac5d03b52548fcbb8af5d2b18c36ec607 100644 (file)
@@ -253,7 +253,7 @@ M: real +minute
 M: number +second
     over second>> + seconds/minutes [ >>second ] dip +minute ;
 
-: (time+) ( timestamp duration -- timestamp' duration )
+: (time+) ( timestamp duration -- timestamp duration )
     {
         [ second>> +second ]
         [ minute>> +minute ]
@@ -312,8 +312,11 @@ DEFER: time-
 : convert-timezone! ( timestamp duration -- timestamp )
     [ over gmt-offset>> time- (time+) drop ] [ >>gmt-offset ] bi ;
 
+: >local-time! ( timestamp -- timestamp )
+    gmt-offset-duration convert-timezone! ;
+
 : >local-time ( timestamp -- timestamp' )
-    clone gmt-offset-duration convert-timezone! ;
+    clone >local-time! ;
 
 : >gmt! ( timestamp -- timestamp )
     instant convert-timezone! ;
@@ -366,6 +369,7 @@ M: timestamp <=> [ >gmt tuple-slots ] compare ;
     [ day-of-year ] [ day-of-week [ 7 ] when-zero ] bi - 10 + 7 /i ;
 
 DEFER: end-of-year
+
 : week-number ( timestamp -- [1,53] )
     dup (week-number) {
         {  0 [ year>> 1 - end-of-year (week-number) ] }
@@ -880,6 +884,7 @@ CONSTANT: weekday-offsets { 0 0 1 2 3 4 5 }
     + 1 - julian-day-number>date <date> ;
 
 GENERIC: weeks-in-week-year ( obj -- n )
+
 M: integer weeks-in-week-year
     { [ 1 1 <date> thursday? ] [ 12 31 <date> thursday? ] } 1|| 53 52 ? ;