Paste: a few time-related utils

Author: randy7
Mode: factor
Date: Thu, 26 Mar 2009 09:56:49
Plain Text |
: +gt+? ( n1 n2 -- ? ) 
    <=> +gt+ eq? ;

: time-before? ( timestamp -- ? )
    now time- second>> 0 < ;
    
: max-neg ( x y -- x/y )
    2array [ 0 < ] filter
    dup empty? [ "dude, they're both non-negative numbers" throw ] when
    [ <=> ] sort peek ;
    
    
: time-max-neg ( time1 time2 -- time1/time2 )
    2array [ time-before? ] filter
    dup empty? [ "dude, they're both in the future! WHOA" throw ] when
    [ <=> ] sort peek ;
    
: last-weekday ( n -- timestamp )
    [ now now [ 7 - ] change-day ] dip [ day-this-week ] curry bi@ time-max-neg ; ! 2 different time objects

: closest-past-weekdays ( -- seq )
    6 [0,b] [ last-weekday ] map ;

Annotation: some more

Author: randy7
Mode: factor
Date: Wed, 8 Apr 2009 11:03:28
Plain Text |
    
: last-sunday    ( -- timestamp ) 0 last-weekday ; inline
: last-monday    ( -- timestamp ) 1 last-weekday ; inline
: last-tuesday   ( -- timestamp ) 2 last-weekday ; inline
: last-wednesday ( -- timestamp ) 3 last-weekday ; inline
: last-thursday  ( -- timestamp ) 4 last-weekday ; inline
: last-friday    ( -- timestamp ) 5 last-weekday ; inline
: last-saturday  ( -- timestamp ) 6 last-weekday ; inline

New Annotation

Summary:
Author:
Mode:
Body: