calendar: Add yesterday, tomorrow, o'clock, am, pm.
parent
99db5b68d7
commit
33ae7abb23
|
@ -447,6 +447,12 @@ M: timestamp day-name day-of-week day-names nth ;
|
|||
: today ( -- timestamp )
|
||||
now midnight ; inline
|
||||
|
||||
: tomorrow ( -- timestamp )
|
||||
1 days hence midnight ; inline
|
||||
|
||||
: yesterday ( -- timestamp )
|
||||
1 days ago midnight ; inline
|
||||
|
||||
: beginning-of-month ( timestamp -- new-timestamp )
|
||||
midnight 1 >>day ; inline
|
||||
|
||||
|
@ -545,6 +551,20 @@ M: timestamp december clone 12 >>month ;
|
|||
: beginning-of-week ( timestamp -- new-timestamp )
|
||||
midnight sunday ;
|
||||
|
||||
: o'clock ( timestamp n -- new-timestamp )
|
||||
[ midnight ] dip >>hour ;
|
||||
|
||||
ERROR: twelve-hour-expected n ;
|
||||
|
||||
: check-twelve-hour ( n -- n )
|
||||
dup 0 12 between? [ twelve-hour-expected ] unless ;
|
||||
|
||||
: am ( timestamp n -- new-timestamp )
|
||||
check-twelve-hour o'clock ;
|
||||
|
||||
: pm ( timestamp n -- new-timestamp )
|
||||
check-twelve-hour 12 + o'clock ;
|
||||
|
||||
GENERIC: beginning-of-year ( object -- new-timestamp )
|
||||
M: timestamp beginning-of-year beginning-of-month 1 >>month ;
|
||||
M: integer beginning-of-year <year> ;
|
||||
|
|
Loading…
Reference in New Issue