Skip to content

no conversion between java.sql.Date and LocalDate #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Heliosmaster opened this issue Mar 15, 2017 · 4 comments
Closed

no conversion between java.sql.Date and LocalDate #5

Heliosmaster opened this issue Mar 15, 2017 · 4 comments
Milestone

Comments

@Heliosmaster
Copy link

Heliosmaster commented Mar 15, 2017

I see no reason why there should not be a conversion between these two types.

The following code serve the purpose:

(defn from-sql-date [^java.sql.Date date]
  (.toLocalDate date))
(defn to-sql-date [^java.time.LocalDate date]
  (java.sql.Date/valueOf date))

What do you think?

@dm3
Copy link
Owner

dm3 commented Mar 17, 2017

I've thought about it before and I think you're right. However, due to the way conversions work in the library, we need to think about it more carefully.

This conversion loses information when going java.Date -> LocalDate, which is fine, and gains implicit information (time zone) when going the other way. I'm trying to avoid the implicit conversions of this kind whenever possible.

I definitely think it would be beneficial having j/to-java-date, j/to-sql-date and j/to-sql-timestamp go through the same conversion mechanism the other temporal entities use. This way you could say (j/to-sql-date (j/local-date 2017 1 1) "UTC") instead of going through j/instant. Currently the best you can do is (j/to-sql-date (j/instant (j/local-date 2017 1 1) "UTC")).

@Heliosmaster
Copy link
Author

I agree with you, and from the java types you're definitely right (about gaining and losing implicit information).

What makes this a bit of an awkward situation is that the "real" SQL date type (for example in PostgreSQL, does not have a timestamp even though java.sql.Date has one. So in my mind, it was

LocalDate <-> java.sql.Date <-> SQL Date

and even though in between some implicit information is added and removed, it turns out fine at both ends. But i agree that we need to think about it carefully :(

@dm3 dm3 added the enhancement label Apr 6, 2017
@dm3 dm3 added this to the 0.2.3 milestone Apr 6, 2017
@dm3
Copy link
Owner

dm3 commented May 7, 2017

@Heliosmaster - I've added a few more functions/conversions. Do you think we can close the issue now?

@Heliosmaster
Copy link
Author

Yeah thanks the issue can be closed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants