[#149] Add java.time.* classes
This commit is contained in:
parent
316cce2b59
commit
1b1e564288
6 changed files with 152 additions and 3 deletions
|
|
@ -689,6 +689,10 @@ bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (dr
|
||||||
jet --pretty > deps.edn
|
jet --pretty > deps.edn
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Print current time in California
|
||||||
|
|
||||||
|
See [examples/pst.clj](https://github.com/borkdude/babashka/blob/master/examples/pst.clj)
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|
|
||||||
- [adgoji](https://www.adgoji.com/) for financial support
|
- [adgoji](https://www.adgoji.com/) for financial support
|
||||||
|
|
|
||||||
7
examples/pst.clj
Executable file
7
examples/pst.clj
Executable file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
(def now (java.time.ZonedDateTime/now))
|
||||||
|
(def LA-timezone (java.time.ZoneId/of "America/Los_Angeles"))
|
||||||
|
(def LA-time (.withZoneSameInstant now LA-timezone))
|
||||||
|
(def pattern (java.time.format.DateTimeFormatter/ofPattern "HH:mm"))
|
||||||
|
(println (.format LA-time pattern))
|
||||||
100
reflection.json
100
reflection.json
|
|
@ -163,6 +163,106 @@
|
||||||
"allPublicMethods" : true,
|
"allPublicMethods" : true,
|
||||||
"allPublicFields" : true,
|
"allPublicFields" : true,
|
||||||
"allPublicConstructors" : true
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.Clock",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.DateTimeException",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.DayOfWeek",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.Duration",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.Instant",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.LocalDate",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.LocalDateTime",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.LocalTime",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.Month",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.MonthDay",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.OffsetDateTime",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.OffsetTime",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.Period",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.Year",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.YearMonth",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.ZoneId",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.ZoneOffset",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.ZonedDateTime",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.format.DateTimeFormatter",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
|
}, {
|
||||||
|
"name" : "java.time.temporal.TemporalAccessor",
|
||||||
|
"allPublicMethods" : true,
|
||||||
|
"allPublicFields" : true,
|
||||||
|
"allPublicConstructors" : true
|
||||||
}, {
|
}, {
|
||||||
"name" : "java.util.concurrent.LinkedBlockingQueue",
|
"name" : "java.util.concurrent.LinkedBlockingQueue",
|
||||||
"allPublicMethods" : true,
|
"allPublicMethods" : true,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,26 @@
|
||||||
java.nio.file.attribute.FileAttribute
|
java.nio.file.attribute.FileAttribute
|
||||||
java.nio.file.attribute.PosixFilePermission
|
java.nio.file.attribute.PosixFilePermission
|
||||||
java.nio.file.attribute.PosixFilePermissions
|
java.nio.file.attribute.PosixFilePermissions
|
||||||
|
java.time.format.DateTimeFormatter
|
||||||
|
java.time.Clock
|
||||||
|
java.time.DateTimeException
|
||||||
|
java.time.DayOfWeek
|
||||||
|
java.time.Duration
|
||||||
|
java.time.Instant
|
||||||
|
java.time.LocalDate
|
||||||
|
java.time.LocalDateTime
|
||||||
|
java.time.LocalTime
|
||||||
|
java.time.Month
|
||||||
|
java.time.MonthDay
|
||||||
|
java.time.OffsetDateTime
|
||||||
|
java.time.OffsetTime
|
||||||
|
java.time.Period
|
||||||
|
java.time.Year
|
||||||
|
java.time.YearMonth
|
||||||
|
java.time.ZonedDateTime
|
||||||
|
java.time.ZoneId
|
||||||
|
java.time.ZoneOffset
|
||||||
|
java.time.temporal.TemporalAccessor
|
||||||
java.util.regex.Pattern
|
java.util.regex.Pattern
|
||||||
sun.nio.fs.UnixPath ;; included because of permission check
|
sun.nio.fs.UnixPath ;; included because of permission check
|
||||||
]
|
]
|
||||||
|
|
|
||||||
19
test/babashka/java_time_test.clj
Normal file
19
test/babashka/java_time_test.clj
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
(ns babashka.java-time-test
|
||||||
|
(:require
|
||||||
|
[babashka.test-utils :as test-utils]
|
||||||
|
[clojure.edn :as edn]
|
||||||
|
[clojure.test :as test :refer [deftest is]]))
|
||||||
|
|
||||||
|
(defn bb [expr]
|
||||||
|
(edn/read-string (apply test-utils/bb nil [(str expr)])))
|
||||||
|
|
||||||
|
(deftest java-time-test
|
||||||
|
(is (= "2019-12-18" (bb '(str (java.time.LocalDate/of 2019 12 18)))))
|
||||||
|
(is (= "2019-12-01" (bb '(str
|
||||||
|
(-> (java.time.LocalDate/of 2019 12 18)
|
||||||
|
(.minusDays 17))))))
|
||||||
|
(is (= "MONDAY" (bb '(str java.time.DayOfWeek/MONDAY))))
|
||||||
|
(is (= "18-12-2019 16:01:41"
|
||||||
|
(bb '(.format
|
||||||
|
(java.time.LocalDateTime/parse "2019-12-18T16:01:41.485")
|
||||||
|
(java.time.format.DateTimeFormatter/ofPattern "dd-MM-yyyy HH:mm:ss"))))))
|
||||||
|
|
@ -3,12 +3,11 @@
|
||||||
[babashka.main :as main]
|
[babashka.main :as main]
|
||||||
[babashka.test-utils :as test-utils]
|
[babashka.test-utils :as test-utils]
|
||||||
[clojure.edn :as edn]
|
[clojure.edn :as edn]
|
||||||
|
[clojure.java.io :as io]
|
||||||
[clojure.java.shell :refer [sh]]
|
[clojure.java.shell :refer [sh]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.test :as test :refer [deftest is testing]]
|
[clojure.test :as test :refer [deftest is testing]]
|
||||||
[clojure.java.io :as io]
|
[sci.core :as sci]))
|
||||||
[sci.core :as sci]
|
|
||||||
[clojure.test :as t]))
|
|
||||||
|
|
||||||
(defn bb [input & args]
|
(defn bb [input & args]
|
||||||
(edn/read-string (apply test-utils/bb (when (some? input) (str input)) (map str args))))
|
(edn/read-string (apply test-utils/bb (when (some? input) (str input)) (map str args))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue