]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar: 12am is midnight, 12pm is noon.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Dec 2020 05:35:05 +0000 (21:35 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Dec 2020 05:35:05 +0000 (21:35 -0800)
basis/calendar/calendar-tests.factor
basis/calendar/calendar.factor

index 6c67378ad0cc9d6edcb0774480de478aeb546678..47b688602fc07797766ba70b590810c91c5aff47 100644 (file)
@@ -130,6 +130,26 @@ IN: calendar
 { t } [ 2004 1 1 23 0 0 9+1/2 hours <timestamp> >gmt
         2004 1 1 13 30 0 instant <timestamp> = ] unit-test
 
+{ t } [
+    2004 1 1 3 0 0 instant <timestamp>
+    2004 1 1 1 0 0 instant <timestamp> 3 am =
+] unit-test
+
+{ t } [
+    2004 1 1 0 0 0 instant <timestamp>
+    2004 1 1 1 0 0 instant <timestamp> 12 am =
+] unit-test
+
+{ t } [
+    2004 1 1 12 0 0 instant <timestamp>
+    2004 1 1 1 0 0 instant <timestamp> 12 pm =
+] unit-test
+
+{ t } [
+    2004 1 1 23 0 0 instant <timestamp>
+    2004 1 1 1 0 0 instant <timestamp> 11 pm =
+] unit-test
+
 { +eq+ } [ 2004 1 1 13 30 0 instant <timestamp>
         2004 1 1 12 30 0 -1 hours <timestamp> <=> ] unit-test
 
index 452ad48282f40c1a0926a7034d4fbdffb144d148..bdedb07227622913df7aa1bb993042cedfa3754e 100644 (file)
@@ -768,10 +768,10 @@ CONSTANT: weekday-offsets { 0 0 1 2 3 4 5 }
     [ midnight ] dip >>hour ;
 
 : am ( timestamp n -- timestamp )
-    0 12 [a,b] check-interval o'clock ;
+    1 12 [a,b] check-interval dup 12 = [ drop 0 ] when o'clock ;
 
 : pm ( timestamp n -- timestamp )
-    0 12 [a,b] check-interval 12 + o'clock ;
+    1 12 [a,b] check-interval dup 12 = [ drop 0 ] when 12 + o'clock ;
 
 : time-since-midnight ( timestamp -- duration )
     instant swap >time< set-time ;