]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar: Add yesterday, tomorrow, o'clock, am, pm.
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Oct 2012 16:46:11 +0000 (09:46 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Oct 2012 16:46:11 +0000 (09:46 -0700)
basis/calendar/calendar.factor

index 45644b035c8260874b31b7ab944c6468dda94aa0..85b0ba7189d2de51299454f77633433a95775579 100644 (file)
@@ -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> ;