 M: number +second
     over second>> + seconds/minutes [ >>second ] dip +minute ;
 
-: (time+) ( timestamp duration -- timestamp duration )
+: (time+) ( timestamp duration -- timestamp )
     {
         [ second>> +second ]
         [ minute>> +minute ]

ALIAS: last-day-of-week saturday

: day< ( timestamp quot -- timestamp )
    over clone [ call dup ] dip after=? [ -7 days (time+) drop ] when ; inline
: day<= ( timestamp quot -- timestamp )
    over clone [ call dup ] dip after? [ -7 days (time+) drop ] when ; inline
: day> ( timestamp quot -- timestamp )
    over clone [ call dup ] dip before=? [ 7 days (time+) drop ] when ; inline
: day>= ( timestamp quot -- timestamp )
    over clone [ call dup ] dip before? [ 7 days (time+) drop ] when ; inline

: sunday< ( timestamp -- timestamp ) [ sunday ] day< ;
: monday< ( timestamp -- timestamp ) [ monday ] day< ;

    gmt-offset-duration >>gmt-offset ; inline

: convert-timezone ( timestamp duration -- timestamp )
    [ over gmt-offset>> time- (time+) ] [ >>gmt-offset ] bi ;

: >local-time ( timestamp -- timestamp )
    gmt-offset-duration convert-timezone ;
