Create initial project structure with tests and reader
This commit is contained in:
6
src/challenge/core.clj
Normal file
6
src/challenge/core.clj
Normal file
@@ -0,0 +1,6 @@
|
||||
(ns challenge.core
|
||||
(:require [clojure.set :as set])
|
||||
(:import (java.time LocalDate Period)
|
||||
(org.threeten.extra LocalDateRange)))
|
||||
|
||||
(defn difference [& input])
|
||||
34
src/challenge/readers.clj
Normal file
34
src/challenge/readers.clj
Normal file
@@ -0,0 +1,34 @@
|
||||
(ns challenge.readers
|
||||
(:import (org.threeten.extra LocalDateRange)))
|
||||
|
||||
(defn local-date-range [s] (LocalDateRange/parse s))
|
||||
|
||||
(defn local-date-range-as-iso-interval
|
||||
"Print the given LocalDateRange `ldr` as an ISO 8601-1:2019 interval in
|
||||
<start>/<duration> format."
|
||||
[ldr]
|
||||
{:pre [(instance? LocalDateRange ldr)]}
|
||||
(let [start (.getStart ldr)
|
||||
period (.toPeriod ldr)]
|
||||
;; NB: when the start date is the first day of the month and the duration is
|
||||
;; one month, consider printing the interval as "YYYY-MM/P1M". This has the
|
||||
;; advantage of naturally segregating month intervals from day intervals in
|
||||
;; lexical sorts but has the disadvantage of not being parseable by the
|
||||
;; LocalDateRange class nor by its sibling Interval class.
|
||||
(str start "/" period)))
|
||||
|
||||
;; We elect to print a LocalDateRange using the ISO 8601-1:2019 <start>/<period>
|
||||
;; representation. This is a compact and standardized representation that high-
|
||||
;; lights our expected use case of specific periods (one day and one month).
|
||||
;; The use of a LocalDate to represent the date-only start point is not well
|
||||
;; publicized, probably because the relevant ISO standard (ISO 8601-2:2019) is
|
||||
;; aggressively copyrighted and the use cases are few compared to other elements
|
||||
;; of the standard.
|
||||
(defmethod print-dup LocalDateRange
|
||||
[o ^java.io.Writer w]
|
||||
(doto w
|
||||
(.write "#st/local-date-range \"")
|
||||
(.write (local-date-range-as-iso-interval o))
|
||||
(.write "\"")))
|
||||
|
||||
(defmethod print-method LocalDateRange [o ^java.io.Writer w] (print-dup o w))
|
||||
1
src/data_readers.clj
Normal file
1
src/data_readers.clj
Normal file
@@ -0,0 +1 @@
|
||||
{st/local-date-range challenge.readers/local-date-range}
|
||||
0
src/data_readers.edn
Normal file
0
src/data_readers.edn
Normal file
Reference in New Issue
Block a user