: 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