]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar: change >gmt, >local-time to clone.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 16 Dec 2020 22:50:11 +0000 (14:50 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 16 Dec 2020 22:50:11 +0000 (14:50 -0800)
Adding convert-gmt and convert-local-time if you don't want to clone.

basis/calendar/calendar-docs.factor
basis/calendar/calendar.factor
basis/calendar/format/format.factor
basis/windows/time/time.factor
core/vocabs/parser/parser.factor
extra/time/windows/windows.factor

index 5057209b4edf776c6f9167ffb8bcf3c2080be403..e2fa95d4e76e3a0d4cd9d3e0b0d0caa106835a81 100644 (file)
@@ -272,8 +272,8 @@ HELP: convert-timezone
 } ;
 
 HELP: >local-time
-{ $values { "timestamp" timestamp } }
-{ $description "Converts the " { $snippet "timestamp" } " to the timezone of your computer." }
+{ $values { "timestamp" timestamp } { "timestamp'" timestamp } }
+{ $description "Converts the " { $snippet "timestamp" } " to the timezone of your computer, returning a new " { $link timestamp } " instance." }
 { $examples
     { $example "USING: accessors calendar kernel prettyprint ;"
                "now now-gmt >local-time [ gmt-offset>> ] same? ."
@@ -282,8 +282,8 @@ HELP: >local-time
 } ;
 
 HELP: >gmt
-{ $values { "timestamp" timestamp } }
-{ $description "Converts the " { $snippet "timestamp" } " to the GMT timezone." }
+{ $values { "timestamp" timestamp } { "timestamp'" timestamp } }
+{ $description "Converts the " { $snippet "timestamp" } " to the GMT timezone, returning a new " { $link timestamp } " instance." }
 { $examples
     { $example "USING: accessors calendar kernel prettyprint ;"
                "now >gmt gmt-offset>> hour>> ."
@@ -301,7 +301,7 @@ HELP: gmt
 { $description "Set the time zone to GMT." }
 { $notes "The time is not converted, if you want that then call " { $link >gmt } "." } ;
 
-{ local-time >local-time gmt >gmt utc >utc convert-timezone } related-words
+{ local-time >local-time convert-local-time gmt >gmt convert-gmt utc >utc convert-utc convert-timezone } related-words
 
 HELP: duration*
 { $values { "obj1" object } { "obj2" object } { "obj3" object } }
index 19af136e1b2fcd0d036773b45582482ef1888d8b..7d65f99d21dbcc454340d253d20072bae8f357a2 100644 (file)
@@ -311,35 +311,38 @@ DEFER: time-
 : convert-timezone ( timestamp duration -- timestamp )
     [ over gmt-offset>> time- (time+) ] [ >>gmt-offset ] bi ;
 
-: >local-time ( timestamp -- timestamp )
+: convert-local-time ( timestamp -- timestamp )
     gmt-offset-duration convert-timezone ;
 
-: >gmt ( timestamp -- timestamp )
+: convert-gmt ( timestamp -- timestamp )
     instant convert-timezone ;
 
-ALIAS: utc gmt
-ALIAS: >utc >gmt
+: >local-time ( timestamp -- timestamp' )
+    clone convert-local-time ;
 
-M: timestamp <=> [ clone >gmt tuple-slots ] compare ;
+: >gmt ( timestamp -- timestamp' )
+    clone convert-gmt ;
 
-<PRIVATE
+: >timezone ( timestamp duration -- timestamp' )
+    [ clone ] [ convert-timezone ] bi* ;
 
-: same-times? ( timestamp1 timestamp2 quot -- ? )
-    [ clone >gmt ] prepose same? ; inline
+ALIAS: utc gmt
+ALIAS: convert-utc convert-gmt
+ALIAS: >utc >gmt
 
-PRIVATE>
+M: timestamp <=> [ >gmt tuple-slots ] compare ;
 
 : same-year? ( ts1 ts2 -- ? )
-    [ slots{ year } ] same-times? ;
+    [ >gmt slots{ year } ] same? ;
 
 : quarter ( timestamp -- [1,4] )
     month>> 3 /i 1 + ; inline
 
 : same-quarter? ( ts1 ts2 -- ? )
-    [ [ year>> ] [ quarter ] bi 2array ] same-times? ;
+    [ >gmt [ year>> ] [ quarter ] bi 2array ] same? ;
 
 : same-month? ( ts1 ts2 -- ? )
-    [ slots{ year month } ] same-times? ;
+    [ >gmt slots{ year month } ] same? ;
 
 :: (day-of-year) ( year month day -- n )
     month days-until nth day + {
@@ -351,7 +354,7 @@ PRIVATE>
     >date< (day-of-year) ;
 
 : same-day? ( ts1 ts2 -- ? )
-    [ slots{ year month day } ] same-times? ;
+    [ >gmt slots{ year month day } ] same? ;
 
 : (day-of-week) ( year month day -- n )
     ! Zeller Congruence
@@ -379,16 +382,16 @@ DEFER: end-of-year
     } case ;
 
 : same-week? ( ts1 ts2 -- ? )
-    [ [ year>> ] [ week-number ] bi 2array ] same-times? ;
+    [ >gmt [ year>> ] [ week-number ] bi 2array ] same? ;
 
 : same-hour? ( ts1 ts2 -- ? )
-    [ slots{ year month day hour } ] same-times? ;
+    [ >gmt slots{ year month day hour } ] same? ;
 
 : same-minute? ( ts1 ts2 -- ? )
-    [ slots{ year month day hour minute } ] same-times? ;
+    [ >gmt slots{ year month day hour minute } ] same? ;
 
 : same-second? ( ts1 ts2 -- ? )
-    [ slots{ year month day hour minute second } ] same-times? ;
+    [ >gmt slots{ year month day hour minute second } ] same? ;
 
 <PRIVATE
 
index 48a77d196214dd9bbd7ee5a06efeb384efdce555..9126352769e0f7805ce3f1bd8a8580c38d9f3b45 100644 (file)
@@ -110,7 +110,7 @@ M: timestamp year. year>> year. ;
     [ hh:mm:ss ] with-string-writer ;
 
 : timestamp>ymdhms ( timestamp -- str )
-    [ clone >gmt YYYY-MM-DD " " hh:mm:ss ] with-string-writer ;
+    [ >gmt YYYY-MM-DD " " hh:mm:ss ] with-string-writer ;
 
 : write-gmt-offset-hhmm ( gmt-offset -- )
     [ hour>> dup 0 < "-" "+" ? write abs write-00 ] [ mm ] bi ;
@@ -185,10 +185,10 @@ ALIAS: timestamp>rfc822 timestamp>rfc2822
     ] with-string-writer ;
 
 : timestamp>http-string ( timestamp -- str )
-    clone >gmt timestamp>rfc2822 ;
+    >gmt timestamp>rfc2822 ;
 
 : timestamp>cookie-string ( timestamp -- str )
-    clone >gmt timestamp>rfc1036 ;
+    >gmt timestamp>rfc1036 ;
 
 : write-timestamp ( timestamp -- )
     { DAY ", " D " " MONTH " " YYYY " " hh:mm:ss } formatted ;
index 0b6250a60603e7c3bb01ef8f77d53a90d6fd956f..dea0e7de4001e7d32b27afc3f2fe2cc3988cd1a1 100644 (file)
@@ -22,14 +22,14 @@ IN: windows.time
 
 : timestamp>windows-time ( timestamp -- n )
     ! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
-    clone >gmt windows-1601 (time-) 10,000,000 * >integer ;
+    >gmt windows-1601 (time-) 10,000,000 * >integer ;
 
 : windows-time>FILETIME ( n -- FILETIME )
     [ FILETIME <struct> ] dip
     [ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ;
 
 : timestamp>FILETIME ( timestamp -- FILETIME/f )
-    dup [ clone >gmt timestamp>windows-time windows-time>FILETIME ] when ;
+    dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
 
 : FILETIME>timestamp ( FILETIME -- timestamp/f )
     FILETIME>windows-time windows-time>timestamp ;
index 408ef633f44e382bc635357f6228cca515ceffd1..cec44020512964b0acb6b65607fd96efa5227dd2 100644 (file)
@@ -176,7 +176,7 @@ TUPLE: rename word vocab words ;
     <extra-words> qualified-vocabs remove! drop ;
 
 : with-words ( assoc quot -- )
-    [ use-words ] prepose over '[ _ unuse-words ] finally ; inline
+    '[ use-words @ ] over '[ _ unuse-words ] finally ; inline
 
 TUPLE: ambiguous-use-error name words ;
 
index 0b063827726ec456d97bdbd1ef9c1afaa8c23aca..6d6b4e7073c4f98ea93c45fefc26dd511a66bd81 100644 (file)
@@ -5,5 +5,4 @@ windows.kernel32 kernel classes.struct calendar ;
 IN: time.windows
 
 M: windows set-system-time
-    clone >gmt
-    timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ;
+    >gmt timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ;