Giter VIP home page Giter VIP logo

Comments (5)

dm3 avatar dm3 commented on May 26, 2024

Hey, how about:

user=> (j/zoned-date-time (j/instant) (j/zone-id "Europe/London"))
#object[java.time.ZonedDateTime 0x949c79c "2020-01-21T07:47:05.201549Z[Europe/London]"]
user=> (j/offset-date-time (j/instant) (j/zone-offset -3))
#object[java.time.OffsetDateTime 0x79762d73 "2020-01-21T04:48:47.084006-03:00"]

Is this what you were looking for or am I misunderstanding?

from clojure.java-time.

dgr avatar dgr commented on May 26, 2024

Duh. OK, that should work.

I was trying the single-arity call to zoned-date-time and was expecting something in UTC, since Instants are nominally in UTC. Yes, the docs say that Instants don't have a time zone, but if you create one by simply calling jt/instant, it displays one that is in UTC, with the time in UTC relative to the local machine time zone. Seems like Instant-to-ZonedDateTime and back should be relatively painless and not require a time zone.

user=>(jt/zoned-date-time (jt/instant))
Execution error (ExceptionInfo) at java-time.zone/zoned-date-time (zone.clj:152).
Could not convert [#object[java.time.Instant 0x1f74a83b "2020-01-21T20:03:07.347009Z"]] to class java.time.ZonedDateTime!

As an aside, the clojure.java-time docs could be improved in this regard. The clojure.java-time library takes a sometimes not obvious approach to mapping all the functionality in java.time into Clojure. In particular, just by looking at classes in java.time, it isn't clear what functions should be called.

Anyway, with all the comments about possible improvements, I'll close this. There's enough there to do what I need to do. Thanks!

from clojure.java-time.

dm3 avatar dm3 commented on May 26, 2024

Cool.

I'll create an issue for a single-arity zoned-date-time and offset-date-time constructors which would use the current zone.

Do you have a concrete improvement to the docs which you'd like applied?

from clojure.java-time.

dgr avatar dgr commented on May 26, 2024

Good question about concrete improvement to the docs. No, not yet. The biggest issue (if you can call it that), is that clojure.java-time is not simply a thin wrapper around java.time objects, where the user is calling the same java.time methods. Because the conversion graph is generated via macros, the parameters to various functions often display as gensym'd names which aren't helpful. You know that there's an arity-1 function there, but no idea what it might consume.

So, let me think about it and I'll try to submit pull requests that explain things better. I've switched completely to clojure.java-time in all my coding, versus cli-time, so I want to see it grow and prosper.

from clojure.java-time.

Heliosmaster avatar Heliosmaster commented on May 26, 2024

I second this. I spent quite some time trying to figure out how to construct a ZoneDateTime from my instants. In the API, for zoned-date-time, with 2 arities, it says

* two arguments
    + formatter and a string
    + local date-time and a zone id
    + year and month

I think we should explicitly mention the instant.

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.