Skip to content
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

Millisecond information for java.sql.Time is lost when converting to/from LocalTime #74

Open
jeff303 opened this issue Jun 15, 2021 · 1 comment · May be fixed by #90
Open

Millisecond information for java.sql.Time is lost when converting to/from LocalTime #74

jeff303 opened this issue Jun 15, 2021 · 1 comment · May be fixed by #90
Labels

Comments

@jeff303
Copy link

jeff303 commented Jun 15, 2021

Consider the following REPL session, in which version 0.3.2 of the library is being used (as per the deps.edn guide here).

(import java.time.temporal.ChronoField)
(import java.time.temporal.Temporal)
(def my-local-time (t/local-time 1 12 13 456000000))
(t/sql-time my-local-time)
#inst "1970-01-01T07:12:13.000-00:00"

Notice that the millisecond portion (456) is lost. In principle, though, it is possible to build the java.sql.Time instance to have that information:

(let [millis-of-day (.get my-local-time ChronoField/MILLI_OF_DAY)]
  (java.sql.Time. millis-of-day))
#inst "1970-01-01T01:12:13.456-00:00"

The same problem occurs in reverse as well:

(def my-sql-time 
  (let [millis-of-day (.get my-local-time ChronoField/MILLI_OF_DAY)]
    (java.sql.Time. millis-of-day)))
(t/local-time my-sql-time)
#object[java.time.LocalTime 0xda22aa "19:12:13"]

Again, it's possible to preserve that information (probably more elegantly than this):

(import java.time.LocalTime)
(LocalTime/ofNanoOfDay (* 1000000 (.getTime my-sql-time)))
#object[java.time.LocalTime 0x10d98940 "01:12:13.456"]
jeff303 referenced this issue in metabase/metabase Jun 15, 2021
…imezone-handling-test` closer to passing

Reported issue with loss of millisecond portion to/from java.sql.Time: `https://github.com/dm3/clojure.java-time/issues/74`
jeff303 referenced this issue in metabase/metabase Jun 17, 2021
…imezone-handling-test` closer to passing

Reported issue with loss of millisecond portion to/from java.sql.Time: `https://github.com/dm3/clojure.java-time/issues/74`
jeff303 referenced this issue in metabase/metabase Jul 23, 2021
…imezone-handling-test` closer to passing

Reported issue with loss of millisecond portion to/from java.sql.Time: `https://github.com/dm3/clojure.java-time/issues/74`
@dm3 dm3 added the bug label Jul 24, 2021
@frenchy64 frenchy64 linked a pull request Jul 20, 2022 that will close this issue
@frenchy64
Copy link
Collaborator

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

Successfully merging a pull request may close this issue.

3 participants