Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Labels
@jeff303

Description

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"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /