Skip to content

Commit

Permalink
tz as strings in passing in/out of fns other than when working direct…
Browse files Browse the repository at this point in the history
…ly with zones
  • Loading branch information
henryw374 committed Feb 21, 2024
1 parent ea9a6ce commit 41fccb6
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 206 deletions.
4 changes: 2 additions & 2 deletions dev/com/widdindustries/gen/gen/accessors.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
(defn special-accessor [target]
(cond
(:xform-fn target) (:xform-fn target)
(:accessor target) (str "." (:accessor target))
:else nil))
(:accessor target) (symbol (str "." (:accessor target)))
:else nil))

(defn cljc-accessor [feature path]
(let [subject (:tempo (first path))
Expand Down
8 changes: 5 additions & 3 deletions gen_in/constructors.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(ns com.widdindustries.gen.gen-in.constructors
#?(:cljay (:import (java.time LocalDateTime ZonedDateTime))))
#?(:cljay (:import (java.time LocalDateTime ZonedDateTime)))
(:require [com.widdindustries.tempo :as t]
[com.widdindustries.tempo :as t]))

(defn time-from [thing]
(let [hour (get thing :hour 0)
Expand Down Expand Up @@ -41,8 +43,8 @@
(defn zdt-from [thing]
(let [ldt (or (get thing :datetime)
(datetime-from thing))
zone (get thing :timezone)]
#?(:cljay (ZonedDateTime/of ^LocalDateTime ldt ^ZoneId zone)
zone (get thing :timezone)]
#?(:cljay (ZonedDateTime/of ^LocalDateTime ldt ^ZoneId (timezone-parse zone))
:cljs (.toZonedDateTime ^js ldt zone)
:cljc (cljc.java-time.zoned-date-time/of ^LocalDateTime ldt ^ZoneId zone))))

Expand Down
190 changes: 132 additions & 58 deletions src/com/widdindustries/tempo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
ZoneId
OffsetDateTime
OffsetTime]
[java.time.temporal Temporal TemporalAmount TemporalUnit ChronoUnit]
[java.time.temporal
Temporal
TemporalAmount
TemporalUnit
ChronoUnit
ChronoField]
[java.util Date]))

(set! *warn-on-reflection* true)
Expand Down Expand Up @@ -62,27 +67,29 @@
[]
(Clock/systemDefaultZone))

(defn clock-offset [offset-or-zone])

(defn greater [x y] (if (neg? (compare x y)) y x))

(defn
max
"Find the latest of the given arguments. Callers should ensure that no\n argument is nil."
"Find the latest of the given arguments. Callers should ensure that no\r\n argument is nil."
[arg & args]
(assert (every? some? (cons arg args)))
(reduce
(fn* [p1__81481# p2__81482#] (greater p1__81481# p2__81482#))
(fn* [p1__38368# p2__38369#] (greater p1__38368# p2__38369#))
arg
args))

(defn lesser [x y] (if (neg? (compare x y)) x y))

(defn
min
"Find the earliest of the given arguments. Callers should ensure that no\n argument is nil."
"Find the earliest of the given arguments. Callers should ensure that no\r\n argument is nil."
[arg & args]
(assert (every? some? (cons arg args)))
(reduce
(fn* [p1__81483# p2__81484#] (lesser p1__81483# p2__81484#))
(fn* [p1__38370# p2__38371#] (lesser p1__38370# p2__38371#))
arg
args))

Expand Down Expand Up @@ -144,39 +151,103 @@
(unit-amount [_])
(unit-accessor [_ x]))

(def nanos-unit ChronoUnit/NANOS)
(defprotocol Property (unit [_]) (field [_]))

(def
nanos-property
(reify
Property
(unit [_] ChronoUnit/NANOS)
(field [_] ChronoField/NANO_OF_SECOND)))

(def
micros-property
(reify
Property
(unit [_] ChronoUnit/MICROS)
(field [_] ChronoField/MICRO_OF_SECOND)))

(def micros-unit ChronoUnit/MICROS)
(def
millis-property
(reify
Property
(unit [_] ChronoUnit/MILLIS)
(field [_] ChronoField/MILLI_OF_SECOND)))

(def millis-unit ChronoUnit/MILLIS)
(def
seconds-property
(reify
Property
(unit [_] ChronoUnit/SECONDS)
(field [_] ChronoField/SECOND_OF_MINUTE)))

(def seconds-unit ChronoUnit/SECONDS)
(def
minutes-property
(reify
Property
(unit [_] ChronoUnit/MINUTES)
(field [_] ChronoField/MINUTE_OF_HOUR)))

(def minutes-unit ChronoUnit/MINUTES)
(def
hours-property
(reify
Property
(unit [_] ChronoUnit/HOURS)
(field [_] ChronoField/HOUR_OF_DAY)))

(def hours-unit ChronoUnit/HOURS)
(def
days-property
(reify
Property
(unit [_] ChronoUnit/DAYS)
(field [_] ChronoField/DAY_OF_MONTH)))

(def days-unit ChronoUnit/DAYS)
(def
months-property
(reify
Property
(unit [_] ChronoUnit/MONTHS)
(field [_] ChronoField/MONTH_OF_YEAR)))

(def months-unit ChronoUnit/MONTHS)
(def
years-property
(reify
Property
(unit [_] ChronoUnit/YEARS)
(field [_] ChronoField/YEAR)))

(def years-unit ChronoUnit/YEARS)
(defn
with
[temporal value property]
(.with
^Temporal temporal
^{:tag TemporalField}
(field property)
^long value))

(defn until [v1 v2 unit] (.until ^Temporal v1 v2 unit))
(defn until [v1 v2 property] (.until ^Temporal v1 v2 (unit property)))

(defn
>>
([temporal temporal-amount]
(.plus ^Temporal temporal ^TemporalAmount temporal-amount))
([temporal amount temporal-unit]
(.plus ^Temporal temporal amount ^TemporalUnit temporal-unit)))
([temporal amount temporal-property]
(.plus
^Temporal temporal
amount
^{:tag TemporalUnit}
(unit temporal-property))))

(defn
<<
([temporal temporal-amount]
(.minus ^Temporal temporal ^TemporalAmount temporal-amount))
([temporal amount temporal-unit]
(.minus ^Temporal temporal amount ^TemporalUnit temporal-unit)))
([temporal amount temporal-property]
(.minus
^Temporal temporal
amount
^{:tag TemporalUnit}
(unit temporal-property))))

(defprotocol WeekDay (weekday-number [_]) (english-name [_]))

Expand Down Expand Up @@ -212,30 +283,28 @@

^{:line 31, :column 9} (comment "accessors")

(defn date->month [^LocalDate foo] (-> foo .getMonthValue))

(defn yearmonth->month [^YearMonth foo] (-> foo .getMonthValue))

(defn zdt->month [^ZonedDateTime foo] (-> foo .getMonthValue))

(defn datetime->second [^LocalDateTime foo] (-> foo .getSecond))

(defn zdt->date [^ZonedDateTime foo] (-> foo .toLocalDate))

(defn monthday->month [^MonthDay foo] (-> foo ".getMonthValue"))

(defn datetime->year [^LocalDateTime foo] (-> foo .getYear))

(defn datetime->month [^LocalDateTime foo] (-> foo ".getMonthValue"))
(defn datetime->month [^LocalDateTime foo] (-> foo .getMonthValue))

(defn zdt->year [^ZonedDateTime foo] (-> foo .getYear))

(defn date->month [^LocalDate foo] (-> foo ".getMonthValue"))
(defn monthday->day-of-month [^MonthDay foo] (-> foo .getDayOfMonth))

(defn yearmonth->month [^YearMonth foo] (-> foo ".getMonthValue"))
(defn zdt->year [^ZonedDateTime foo] (-> foo .getYear))

(defn datetime->hour [^LocalDateTime foo] (-> foo .getHour))

(defn yearmonth->year [^YearMonth foo] (-> foo .getYear))

(defn date->day-of-month [^LocalDate foo] (-> foo .getDayOfMonth))

(defn zdt->day-of-month [^ZonedDateTime foo] (-> foo .getDayOfMonth))

(defn zdt->hour [^ZonedDateTime foo] (-> foo .getHour))

(defn zdt->instant [^ZonedDateTime foo] (-> foo .toInstant))
Expand All @@ -247,27 +316,22 @@
[^ZonedDateTime foo]
(-> foo (-> (.getDayOfWeek) (.getValue))))

(defn zdt->month [^ZonedDateTime foo] (-> foo ".getMonthValue"))

(defn zdt->minute [^ZonedDateTime foo] (-> foo .getMinute))

(defn
datetime->day-of-month
[^LocalDateTime foo]
(-> foo .getDayOfMonth))

(defn date->year [^LocalDate foo] (-> foo .getYear))

(defn datetime->date [^LocalDateTime foo] (-> foo .toLocalDate))

(defn
zdt->timezone
[^ZonedDateTime foo]
(-> foo (-> (.getZone) (.getId))))
(defn date->year [^LocalDate foo] (-> foo .getYear))

(defn zdt->second [^ZonedDateTime foo] (-> foo .getSecond))

(defn instant->epochmilli [^Instant foo] (-> foo ".toEpochMilli"))
(defn zdt->day-of-month [^ZonedDateTime foo] (-> foo .getDayOfMonth))

(defn instant->epochmilli [^Instant foo] (-> foo .toEpochMilli))

(defn time->second [^LocalTime foo] (-> foo .getSecond))

Expand All @@ -278,6 +342,11 @@

(defn zdt->datetime [^ZonedDateTime foo] (-> foo .toLocalDateTime))

(defn
zdt->timezone
[^ZonedDateTime foo]
(-> foo (-> (.getZone) (.getId))))

(defn zdt->time [^ZonedDateTime foo] (-> foo .toLocalTime))

(defn datetime->minute [^LocalDateTime foo] (-> foo .getMinute))
Expand All @@ -295,25 +364,27 @@

(defn time->hour [^LocalTime foo] (-> foo .getHour))

(defn monthday->month [^MonthDay foo] (-> foo .getMonthValue))

(defn datetime->nano [^LocalDateTime foo] (-> foo .getNano))

(defn datetime->time [^LocalDateTime foo] (-> foo .toLocalTime))
(defn yearmonth->year [^YearMonth foo] (-> foo .getYear))

(defn monthday->day-of-month [^MonthDay foo] (-> foo .getDayOfMonth))
(defn datetime->time [^LocalDateTime foo] (-> foo .toLocalTime))

^{:line 33, :column 9} (comment "parsers")

(defn datetime-parse [^java.lang.String foo] (LocalDateTime/parse foo))
(defn date-parse [^java.lang.String foo] (LocalDate/parse foo))

(defn time-parse [^java.lang.String foo] (LocalTime/parse foo))
(defn yearmonth-parse [^java.lang.String foo] (YearMonth/parse foo))

(defn zdt-parse [^java.lang.String foo] (ZonedDateTime/parse foo))

(defn date-parse [^java.lang.String foo] (LocalDate/parse foo))
(defn datetime-parse [^java.lang.String foo] (LocalDateTime/parse foo))

(defn monthday-parse [^java.lang.String foo] (MonthDay/parse foo))

(defn yearmonth-parse [^java.lang.String foo] (YearMonth/parse foo))
(defn time-parse [^java.lang.String foo] (LocalTime/parse foo))

(defn instant-parse [^java.lang.String foo] (Instant/parse foo))

Expand All @@ -322,34 +393,34 @@
^{:line 35, :column 9} (comment "nowers")

(defn
datetime-now
([] (LocalDateTime/now))
([^java.time.Clock clock] (LocalDateTime/now clock)))
date-now
([] (LocalDate/now))
([^java.time.Clock clock] (LocalDate/now clock)))

(defn
time-now
([] (LocalTime/now))
([^java.time.Clock clock] (LocalTime/now clock)))
yearmonth-now
([] (YearMonth/now))
([^java.time.Clock clock] (YearMonth/now clock)))

(defn
zdt-now
([] (ZonedDateTime/now))
([^java.time.Clock clock] (ZonedDateTime/now clock)))

(defn
date-now
([] (LocalDate/now))
([^java.time.Clock clock] (LocalDate/now clock)))
datetime-now
([] (LocalDateTime/now))
([^java.time.Clock clock] (LocalDateTime/now clock)))

(defn
monthday-now
([] (MonthDay/now))
([^java.time.Clock clock] (MonthDay/now clock)))

(defn
yearmonth-now
([] (YearMonth/now))
([^java.time.Clock clock] (YearMonth/now clock)))
time-now
([] (LocalTime/now))
([^java.time.Clock clock] (LocalTime/now clock)))

(defn
instant-now
Expand Down Expand Up @@ -407,7 +478,10 @@
(or (get thing :datetime) (datetime-from thing))
zone
(get thing :timezone)]
(ZonedDateTime/of ^LocalDateTime ldt ^ZoneId zone)))
(ZonedDateTime/of
^LocalDateTime ldt
^{:tag ZoneId}
(timezone-parse zone))))

(defn
instant-from
Expand Down
Loading

0 comments on commit 41fccb6

Please sign in to comment.