Skip to content

Commit

Permalink
add MonthDay
Browse files Browse the repository at this point in the history
  • Loading branch information
henryw374 committed Sep 9, 2019
1 parent 6580e58 commit 783f56b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions project.clj
@@ -1,9 +1,9 @@
(defproject time-literals "0.1.2"
(defproject time-literals "0.1.3"
:description "Clojure(Script) tagged literals for jsr-310 entities"
:url "https://github.com/henryw374/time-literals"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[cljs.java-time "0.1.8"]]
:dependencies [[cljs.java-time "0.1.12"]]
:profiles {:dev
{:source-paths ["dev"]
:dependencies [[org.clojure/clojure "1.10.0"]
Expand Down
1 change: 1 addition & 0 deletions src/data_readers.cljc
Expand Up @@ -10,6 +10,7 @@ time/zone time-literals.data-readers/zone
time/day-of-week time-literals.data-readers/day-of-week
time/time time-literals.data-readers/time
time/month time-literals.data-readers/month
time/month-day time-literals.data-readers/month-day
time/duration time-literals.data-readers/duration
time/year time-literals.data-readers/year
time/year-month time-literals.data-readers/year-month
Expand Down
3 changes: 3 additions & 0 deletions src/time_literals/data_readers.cljc
Expand Up @@ -43,6 +43,9 @@
(defn month [x]
(list '. 'java.time.Month 'valueOf x))

(defn month-day [x]
(list '. 'java.time.MonthDay 'parse x))




Expand Down
11 changes: 9 additions & 2 deletions src/time_literals/read_write.cljc
Expand Up @@ -14,7 +14,8 @@
Month
Duration
Year
YearMonth]]
YearMonth
MonthDay]]
[cljs.reader :as reader])]
:clj
[
Expand All @@ -32,7 +33,8 @@
Month
Duration
Year
YearMonth])]))
YearMonth
MonthDay])]))

(defn- print-to-string [t o]
(str "#time/" t " \"" (str o) "\""))
Expand All @@ -48,6 +50,7 @@
(def print-day-of-week (partial print-to-string "day-of-week"))
(def print-time (partial print-to-string "time"))
(def print-month (partial print-to-string "month"))
(def print-month-day (partial print-to-string "month-day"))
(def print-duration (partial print-to-string "duration"))
(def print-year (partial print-to-string "year"))
(def print-year-month (partial print-to-string "year-month"))
Expand All @@ -67,6 +70,7 @@
DayOfWeek (-pr-writer [d writer opts] (-write writer (print-day-of-week d)))
LocalTime (-pr-writer [d writer opts] (-write writer (print-time d)))
Month (-pr-writer [d writer opts] (-write writer (print-month d)))
MonthDay (-pr-writer [d writer opts] (-write writer (print-month-day d)))
Duration (-pr-writer [d writer opts] (-write writer (print-duration d)))
Year (-pr-writer [d writer opts] (-write writer (print-year d)))
YearMonth (-pr-writer [d writer opts] (-write writer (print-year-month d)))
Expand All @@ -84,6 +88,7 @@
#?(:clj (defmethod print-method DayOfWeek [c ^Writer w] (.write w ^String (print-day-of-week c))))
#?(:clj (defmethod print-method LocalTime [c ^Writer w] (.write w ^String (print-time c))))
#?(:clj (defmethod print-method Month [c ^Writer w] (.write w ^String (print-month c))))
#?(:clj (defmethod print-method MonthDay [c ^Writer w] (.write w ^String (print-month-day c))))
#?(:clj (defmethod print-method Duration [c ^Writer w] (.write w ^String (print-duration c))))
#?(:clj (defmethod print-method Year [c ^Writer w] (.write w ^String (print-year c))))
#?(:clj (defmethod print-method YearMonth [c ^Writer w] (.write w ^String (print-year-month c)))))
Expand All @@ -99,6 +104,7 @@
#?(:clj (defmethod print-dup DayOfWeek [c ^Writer w] (.write w ^String (print-day-of-week c))))
#?(:clj (defmethod print-dup LocalTime [c ^Writer w] (.write w ^String (print-time c))))
#?(:clj (defmethod print-dup Month [c ^Writer w] (.write w ^String (print-month c))))
#?(:clj (defmethod print-dup MonthDay [c ^Writer w] (.write w ^String (print-month-day c))))
#?(:clj (defmethod print-dup Duration [c ^Writer w] (.write w ^String (print-duration c))))
#?(:clj (defmethod print-dup Year [c ^Writer w] (.write w ^String (print-year c))))
#?(:clj (defmethod print-dup YearMonth [c ^Writer w] (.write w ^String (print-year-month c))))
Expand All @@ -118,6 +124,7 @@
'time/zone (fn [t] (. ZoneId of t))
'time/day-of-week (fn [t] (. DayOfWeek valueOf t))
'time/month (fn [t] (. Month valueOf t))
'time/month-day (fn [t] (. MonthDay parse t))
})

#?(:cljs
Expand Down
4 changes: 4 additions & 0 deletions test/time_literals/core_test.cljc
Expand Up @@ -6,6 +6,9 @@
#?(:cljs [cljsjs.js-joda-timezone])
#?(:cljs [cljs.java-time.extend-eq-and-compare])))

(time-literals.read-write/print-time-literals-clj!)
(time-literals.read-write/print-time-literals-cljs!)

(defn read-tagged [o]
#?(:clj (clojure.edn/read-string {:readers time-literals.read-write/tags} o)
:cljs (cljs.reader/read-string o)))
Expand All @@ -17,6 +20,7 @@
:cljs nil)
{
:a-month #time/month "JUNE"
:a-month-day #time/month-day "--09-09"
:a-period #time/period "P1D"
:a-date #time/date "2039-01-01"
:a-date-time #time/date-time "2018-07-25T08:08:44.026"
Expand Down

0 comments on commit 783f56b

Please sign in to comment.