Comments (5)
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.
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.
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.
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.
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)
- `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.