|
1 | 1 | (ns java-time.pre-java8 |
2 | 2 | (:require [java-time |
| 3 | + [convert :as jt.c] |
3 | 4 | [local :as jt.l] |
4 | 5 | [temporal :as jt.t] |
5 | 6 | [defconversion :refer [conversion!]]])) |
|
40 | 41 |
|
41 | 42 | (defsqldate java.sql.Date sql-date jt.l/local-date 3 |
42 | 43 | "Creates a `java.sql.Date` out of any combination of arguments valid for |
43 | | - `java-time/local-date` or the LocalDate itself. |
| 44 | + `java-time/local-date` or the `LocalDate` itself. |
44 | 45 |
|
45 | 46 | Please consider using the JSR-310 Java Time types instead of `java.sql.Date` |
46 | 47 | if your drivers support them. |
|
50 | 51 | conversion from/to native JDBC driver DATE types.") |
51 | 52 |
|
52 | 53 | (defsqldate java.sql.Timestamp sql-timestamp jt.l/local-date-time 7 |
53 | | - "Creates a `java.sql.Timestamp` out of any combination of arguments valid for |
54 | | - `java-time/local-date-time` or the LocalDateTime itself. |
| 54 | + "Creates a `java.sql.Timestamp` in the local timezone out of any combination |
| 55 | + of arguments valid for `java-time/local-date-time` or the `LocalDateTime` |
| 56 | + itself. |
| 57 | +
|
| 58 | + The `sql-timestamp` constructor function does not support `Timestamp` |
| 59 | + construction from an `Instant` or a long millis value. Please use |
| 60 | + `instant->sql-timestamp` for this purpose. |
55 | 61 |
|
56 | 62 | Please consider using the JSR-310 Java Time types instead of |
57 | 63 | `java.sql.Timestamp` if your drivers support them. |
|
60 | 66 | as a local date-time (no timezone) for the purposes of conversion from/to native |
61 | 67 | JDBC driver TIMESTAMP types.") |
62 | 68 |
|
| 69 | +(defn instant->sql-timestamp |
| 70 | + "Creates a `java.sql.Timestamp` from the provided `instant-or-millis` - a |
| 71 | + millisecond numeric time value or something convertible to an `Instant`. |
| 72 | +
|
| 73 | + Please consider using the JSR-310 Java Time types instead of |
| 74 | + `java.sql.Timestamp` if your drivers support them. |
| 75 | +
|
| 76 | + `java.sql.Timestamp` is a version of a `java.util.Date` supposed to be used |
| 77 | + as a local date-time (no timezone) for the purposes of conversion from/to native |
| 78 | + JDBC driver TIMESTAMP types." |
| 79 | + [instant-or-millis] |
| 80 | + (if (number? instant-or-millis) |
| 81 | + (java.sql.Timestamp. (long instant-or-millis)) |
| 82 | + (java.sql.Timestamp/from (jt.t/instant instant-or-millis)))) |
| 83 | + |
63 | 84 | (defsqldate java.sql.Time sql-time jt.l/local-time 3 |
64 | 85 | "Creates a `java.sql.Time` out of any combination of arguments valid for |
65 | | - `java-time/local-time` (except the nanos constructor) or the LocalTime |
| 86 | + `java-time/local-time` (except the nanos constructor) or the `LocalTime` |
66 | 87 | itself. |
67 | 88 |
|
68 | 89 | Please consider using the JSR-310 Java Time types instead of `java.sql.Time` |
|
0 commit comments