Comments (6)
How would you parse a string with a predefined formatter?
from clojure.java-time.
Hi, sorry for not responding earlier!
There's already a set of predefined formatters supported by j/format
. These are the formatters defined in java.time.format.DateTimeFormatter:
user=> (keys java-time.format/predefined-formatters)
("iso-offset-time"
"iso-local-time"
"iso-local-date-time"
"iso-offset-date"
"iso-time"
"iso-week-date"
"basic-iso-date"
"rfc-1123-date-time"
"iso-ordinal-date"
"iso-zoned-date-time"
"iso-instant"
"iso-date-time"
"iso-offset-date-time"
"iso-date"
"iso-local-date")
so you can do the following:
user=> (j/format :iso-offset-time (j/zoned-date-time))
"21:10:00.000+01:00"
user=> (j/format :iso-time (j/zoned-date-time))
"21:11:00.000+01:00"
user=> (j/format :iso-date-time (j/zoned-date-time))
"2018-07-12T21:12:00.000+01:00[Europe/London]"
user=> (j/format :iso-local-date (j/zoned-date-time))
"2018-07-12"
We can always improve the documentation if you think this can be made clearer. Happy to review any PR/discuss changes.
from clojure.java-time.
This is really a minor issue. It is nice that j/format
does key processing, but to access the formatters hash-map directly, I made a helper function:
(defn get-formatter
"java-time helper for referencing predefined JavaTime formatters
`format-index` may be a string or a keyword"
[format-index]
(get f/predefined-formatters
(-> format-index
->kebab-case
name)))
with help from camelsnakekebab
A helper wouldn't be necessary if f/predefined-formatters
had key-word keys instead of strings.
from clojure.java-time.
java-time.format/predefined-formatters
is supposed to be private. The only public API namespaces are java-time
and java-time.repl
.
Could you please explain why you need the access to predefined formatters separately from the j/format
function? Maybe we'll think of something to add to the public API.
from clojure.java-time.
How would you parse a string with a predefined formatter?
Like so:
user=> (j/format :iso-offset-time (j/zoned-date-time))
"21:10:00.000+01:00"
You can still reference predefined formats (like :iso-offset-time
) without having them in a map.
See the response by dm3 cfrom Jul 12, 2018.
from clojure.java-time.
Added API comments to j/format
from clojure.java-time.
Related Issues (20)
- `zoned-date-time` with a single argument does not use `java-time.clock/make` HOT 1
- Canadian locale doesn't support AM/PM? HOT 1
- Instant < Interval breaks transitivity
- `not-{before,after}?` broken for equal arguments that need coercion
- t/> comparison and t/plus arithmetic support for java.sql.Timestamp HOT 1
- Fix java.time's brittleness
- Millisecond information for `java.sql.Time` is lost when converting to/from `LocalTime` HOT 1
- Unix timestamp conversion HOT 1
- Various properties gone missing in 0.3.3 HOT 7
- 0.3.3 - Year formatted wrongly on date roll ? HOT 3
- Consider Removing clj-tuple HOT 2
- Minor Clojure 1.11 Alpha 4 compatibility issue HOT 1
- Cut new release for Clojure 1.11 compat? HOT 23
- PriorityQueue class not found in babashka HOT 1
- Babashka Support HOT 1
- Type conversion graph is dependent on evaluation order HOT 1
- Deprecate single segment ns HOT 4
- Things like `java-time[.api]/truncate-to` do not work correctly when underlying protocol is extended HOT 5
- Case bug in https://github.com/dm3/clojure.java-time/blob/master/src/java_time/format.clj#L32 HOT 1
- `not-after?` not semantically equivalent to `<=` despite documentation implying otherwise HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clojure.java-time.