]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.cal: using strftime + tests
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 3 Jan 2017 14:30:59 +0000 (15:30 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 3 Jan 2017 14:31:52 +0000 (15:31 +0100)
extra/tools/cal/cal-tests.factor [new file with mode: 0644]
extra/tools/cal/cal.factor

diff --git a/extra/tools/cal/cal-tests.factor b/extra/tools/cal/cal-tests.factor
new file mode 100644 (file)
index 0000000..ce4115e
--- /dev/null
@@ -0,0 +1,14 @@
+USING: calendar tools.cal.private tools.test ;
+IN: tools.cal.tests
+
+{
+    "    October 2010    "
+} [
+    2010 10 10 <date> month-header
+] unit-test
+
+{
+    "                              2010                              "
+} [
+    2010 10 10 <date> year-header
+] unit-test
index c0be27e16fa81de7ca7aefd269d5d6f9bf64336d..f887585baabbebf71fd91cd26e78cbe31c508c4f 100644 (file)
@@ -1,10 +1,8 @@
 ! Copyright (C) 2016 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
-
-USING: accessors calendar combinators command-line formatting
-grouping io kernel math.parser math.ranges namespaces sequences
-sequences.extras strings.tables ;
-
+USING: accessors calendar combinators command-line
+formatting grouping io kernel math.parser math.ranges namespaces
+sequences sequences.extras strings.tables ;
 IN: tools.cal
 
 <PRIVATE
@@ -16,11 +14,11 @@ IN: tools.cal
     42 "  " pad-tail ;
 
 : month-header ( timestamp -- str )
-    [ month-name ] [ year>> ] bi "%s %s" sprintf
+    "%B %Y" strftime
     20 CHAR: \s pad-center ;
 
 : year-header ( timestamp -- str )
-    year>> "%s" sprintf 64 CHAR: \s pad-center ;
+    "%Y" strftime 64 CHAR: \s pad-center ;
 
 : month-rows ( timestamp -- rows )
     days 7 group day-abbreviations2 prefix format-table ;