This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-02
Channels
- # announcements (11)
- # aws (2)
- # babashka (42)
- # beginners (26)
- # calva (17)
- # cider (1)
- # clara (2)
- # clj-kondo (44)
- # clojars (30)
- # clojure (43)
- # clojure-australia (6)
- # clojure-europe (29)
- # clojure-gamedev (4)
- # clojure-greece (1)
- # clojure-nl (4)
- # clojure-spec (4)
- # clojure-uk (6)
- # clojurescript (28)
- # cursive (16)
- # data-science (1)
- # datahike (4)
- # datomic (26)
- # emacs (6)
- # events (3)
- # fulcro (11)
- # graalvm (7)
- # holy-lambda (118)
- # java (9)
- # jobs (1)
- # leiningen (3)
- # lsp (21)
- # luminus (2)
- # malli (13)
- # membrane-term (1)
- # music (1)
- # nrepl (3)
- # off-topic (38)
- # pedestal (2)
- # polylith (39)
- # re-frame (33)
- # reagent (7)
- # releases (1)
- # remote-jobs (4)
- # rewrite-clj (28)
- # ring (21)
- # sql (2)
- # tools-deps (23)
- # vim (4)
- # xtdb (15)
Did I just discover a bug in the java standard library?
(ns scratchpad
(:import java.text.SimpleDateFormat
(java.time Instant Locale ZoneOffset)
java.time.format.DateTimeFormatter
java.util.Date))
(def pattern-1 "EEE, dd MMM yyyy HH:mm:ss ZZZZ")
(def pattern-2 "EEE, dd MMM yyyy HH:mm:ss ZZ")
(defn format-time [t pat]
(when t
(cond
(instance? Date t)
(.format (new SimpleDateFormat
pat
Locale/ENGLISH) t)
(instance? Instant t)
(.format (DateTimeFormatter/ofPattern pat Locale/ENGLISH)
(.atOffset t ZoneOffset/UTC)))))
(let [inst (Instant/now)
date (Date/from inst)]
[[(format-time inst pattern-1) (format-time date pattern-1)]
[(format-time inst pattern-2) (format-time date pattern-2)]])
Expected:
=> [["Tue, 02 Nov 2021 05:52:02 +0000" "Tue, 02 Nov 2021 05:52:02 +0000"]
["Tue, 02 Nov 2021 05:52:02 +0000" "Tue, 02 Nov 2021 05:52:02 +0000"]]
Actual:
=> [["Tue, 02 Nov 2021 05:52:02 GMT" "Tue, 02 Nov 2021 05:52:02 +0000"]
["Tue, 02 Nov 2021 05:52:02 +0000" "Tue, 02 Nov 2021 05:52:02 +0000"]]
According to the https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/format/DateTimeFormatter.html, "Z"
in a pattern should not yield a localized zone offset.Looks right to me (emphasis mine)
> Offset Z: This formats the offset based on the number of pattern letters. One, two or three letters outputs the hour and minute, without a colon, such as '+0130'. The output will be '+0000' when the offset is zero. Four letters outputs the https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/format/TextStyle.html#FULL form of localized offset, equivalent to four letters of Offset-O. The output will be the corresponding localized offset text if the offset is zero. Five letters outputs the hour, minute, with optional second if non-zero, with colon. It outputs 'Z' if the offset is zero. Six or more letters throws IllegalArgumentException
.
java.util.Date is cursed
easily my least favorite class 🙂
oh yeah I see what you mean
Nice name by the way @danielmartincraig
lol thank you