From 3ead1600d48805a4bd155e5c1e076f4a08c538eb Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 25 Oct 2012 09:46:11 -0700 Subject: [PATCH] calendar: Add yesterday, tomorrow, o'clock, am, pm. --- basis/calendar/calendar.factor | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index 45644b035c..85b0ba7189 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -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 ;