Adding convert-gmt and convert-local-time if you don't want to clone.
} ;
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? ."
} ;
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>> ."
{ $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 } }
: 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 + {
>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
} 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
[ 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 ;
] 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 ;
: 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 ;
<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 ;
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 ;