Code Monkey home page Code Monkey logo

Comments (6)

yayitswei avatar yayitswei commented on May 30, 2024 1

How would you parse a string with a predefined formatter?

from clojure.java-time.

dm3 avatar dm3 commented on May 30, 2024

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.

waffletower avatar waffletower commented on May 30, 2024

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.

dm3 avatar dm3 commented on May 30, 2024

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.

jacobemcken avatar jacobemcken commented on May 30, 2024

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.

dm3 avatar dm3 commented on May 30, 2024

Added API comments to j/format

from clojure.java-time.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.