Calendar: Difference between revisions

Content added Content deleted
Line 1,996: Line 1,996:


(defn month-to-word
(defn month-to-word
"Translate a month from 0 to 11 into its word representation"
"Translate a month from 0 to 11 into its word representation."
[month]
[month]
((vec (.getMonths (new java.text.DateFormatSymbols))) month))
((vec (.getMonths (new java.text.DateFormatSymbols))) month))
Line 2,010: Line 2,010:
(defn normal-date-string
(defn normal-date-string
"Returns a formtted list of strings of the days of the month"
"Returns a formatted list of strings of the days of the month."
[date]
[date]
(map #(join " " %)
(map #(join " " %)
Line 2,023: Line 2,023:
(defn oct-1582-string
(defn oct-1582-string
" Returns a formated list of strings of the days of the month of oct 1582"
"Returns a formatted list of strings of the days of the month of October 1582."
[date]
[date]
(map #(join " " %)
(map #(join " " %)
Line 2,040: Line 2,040:


(defn center-string
(defn center-string
" Return a string that is WIDTH long with STRING centered in it "
"Returns a string that is WIDTH long with STRING centered in it."
[string width]
[string width]
(let [pad (- width (count string))
(let [pad (- width (count string))
Line 2,053: Line 2,053:


(defn calc-columns
(defn calc-columns
"Calcutate the number of columns given the width in CHARACTERS and the
"Calculates the number of columns given the width in CHARACTERS and the
MARGIN SIZE"
MARGIN SIZE."
[characters margin-size]
[characters margin-size]
(loop [cols 0 excess characters ]
(loop [cols 0 excess characters ]
Line 2,062: Line 2,062:


(defn month-vector
(defn month-vector
"Returns a vector with the month name, day-row and days
"Returns a vector with the month name, day-row and days
formatted for printing"
formatted for printing."
[date]
[date]
(vec (concat
(vec (concat
Line 2,074: Line 2,074:


(defn year-vector [date]
(defn year-vector [date]
"Retuns a 2d vector of all the months in the year of DATE"
"Returns a 2d vector of all the months in the year of DATE."
(loop [m [] c (month date)]
(loop [m [] c (month date)]
(if (= c 11 )
(if (= c 11 )
Line 2,083: Line 2,083:


(defn print-months
(defn print-months
"prints the months to standard output with NCOLS and MARGIN "
"Prints the months to standard output with NCOLS and MARGIN."
[ v ncols margin]
[ v ncols margin]
(doseq [r (range (Math/ceil (/ 12 ncols)))]
(doseq [r (range (Math/ceil (/ 12 ncols)))]
Line 2,096: Line 2,096:
(defn print-cal
(defn print-cal
"(print-cal [year [width [margin]]])
"(print-cal [year [width [margin]]])
Print out the calendar for a given YEAR with WIDTH characters wide
Prints out the calendar for a given YEAR with WIDTH characters wide and
with MARGIN spaces between months."
with MARGIN spaces between months."
([]
([]
(print-cal 1969 80 2))
(print-cal 1969 80 2))
Line 2,105: Line 2,105:
(print-cal year width 2))
(print-cal year width 2))
([year width margin]
([year width margin]
(assert (>= width (count day-row)) "width should be more than 20")
(assert (>= width (count day-row)) "Width should be more than 20.")
(assert (> margin 0) "margin needs to be more than 0")
(assert (> margin 0) "Margin needs to be more than 0.")
(let [date (new java.util.GregorianCalendar year 0 1)
(let [date (new java.util.GregorianCalendar year 0 1)
column-count (calc-columns width margin)
column-count (calc-columns width margin)