@@ -312,18 +312,59 @@ less information, e.g. (assuming we're in UTC timezone):
312312=> #object[java.time.LocalTime 0x3a3cd6d5 " 01:00" ]
313313```
314314
315- Any date which can be converted to an instant, can also be converted to pre-Java
316- 8 date types:
315+ #### Legacy Date-Time Types
317316
318- ``` clj
319- (to-java-date (zoned-date-time 2015 9 28 ))
317+ Any date which can be converted to an instant, can also be converted to a
318+ ` java.util.Date ` :
319+
320+ ``` clojure
321+ (java-date (zoned-date-time 2015 9 28 ))
320322=> #inst " 2015-09-27T22:00:00.000-00:00"
321323
322- (to-sql-date (zoned-date-time 2015 9 28 ))
324+ (java-date 50000 )
325+ => #inst " 1970-01-01T00:00:50.000-00:00"
326+ ```
327+
328+ An instance of ` java.util.Date ` serves the same purpose as the new
329+ ` java.time.Instant ` . It's a machine timestamp which isn't aware of the
330+ timezone. Please, do not get confused by the way it is printed by the Clojure
331+ printer - the UTC timezone is applied during formatting.
332+
333+ Sometimes you'll have to work with the legacy ` java.sql.Date/Time/Timestamp `
334+ types. The correspondence between the legacy types and the new Date-Time
335+ entities is as follows:
336+
337+ * ` java.time.LocalDate ` - ` java.sql.Date `
338+ * ` java.time.LocalDateTime ` - ` java.sql.Timestamp `
339+ * ` java.time.LocalTime ` - ` java.sql.Time `
340+
341+ ``` clojure
342+ (sql-date 2015 9 28 )
323343=> #inst " 2015-09-27T22:00:00.000-00:00"
324344
325- (to-sql-timestamp (zoned-date-time 2015 9 28 ))
326- => #inst " 2015-09-27T22:00:00.000000000-00:00"
345+ (sql-timestamp 2015 9 28 10 20 30 4000000 )
346+ => #inst " 2015-09-28T09:20:30.004-00:00"
347+
348+ (sql-time 10 20 30 )
349+ => #inst " 1970-01-01T09:20:30.000-00:00"
350+ ```
351+
352+ The results of the above calls get printed as ` #inst ` because all of the
353+ ` java.sql.Date/Time/Timestamp ` are subtypes of ` java.util.Date ` .
354+ Coincidentally, this makes it impossible to plug the ` java.sql.* ` types into
355+ the Clojure.Java-Time conversion graph.
356+
357+ Conversions to the legacy types also go the other way around:
358+
359+ ``` clojure
360+ (j/local-date (j/sql-date 2015 9 28 ))
361+ #object[java.time.LocalDate " 2015-09-28" ]
362+
363+ (j/local-date-time (j/sql-timestamp 2015 9 28 10 20 30 4000000 ))
364+ #object[java.time.LocalDateTime " 2015-09-28T10:20:30.004" ]
365+
366+ (j/local-time (j/sql-time 10 20 30 ))
367+ #object[java.time.LocalTime " 10:20:30" ]
327368```
328369
329370#### Three-Ten Extra
@@ -335,7 +376,7 @@ project, you will get an `Interval`, `AmPm`, `DayOfMonth`, `DayOfYear`,
335376An interval can be constructed from two entities that can be converted to
336377instants:
337378
338- ``` clj
379+ ``` clojure
339380(interval (offset-date-time 2015 1 1 ) (zoned-date-time 2016 1 1 ))
340381=> #<org.threeten.extra.Interval 2015 -01-01 T00:00:00Z/2016 -01-01 T00:00:00Z>
341382
@@ -354,7 +395,7 @@ instants:
354395Bonus! if you have Joda Time on the classpath (either directly, or via
355396` clj-time ` ), you can seamlessly convert from Joda Time to Java Time types:
356397
357- ``` clj
398+ ``` clojure
358399(java-time.repl/show-path org.joda.time.DateTime java.time.OffsetTime)
359400=> {:cost 2.0 ,
360401 :path [[#<java_time.graph.Types@15e43 c24 [org.joda.time.DateTime]>
@@ -374,7 +415,7 @@ you to influence the date-times create using default constructors ala Joda's
374415` DateTimeUtils/setCurrentMillisSystem ` . Clojure.Java-Time tries to fix that with
375416the ` with-clock ` macro and the corresponding ` with-clock-fn ` function:
376417
377- ``` clj
418+ ``` clojure
378419(zone-id )
379420=> #<java.time.ZoneRegion Europe/London>
380421
@@ -391,7 +432,7 @@ Date-Time entities are composed of date fields, while Duration entities are
391432composed of time units. You can see all of the predefined fields and units
392433via the ` java-time.repl ` ns:
393434
394- ``` clj
435+ ``` clojure
395436(java-time.repl/show-fields )
396437=> (:aligned-day-of-week-in-month
397438 :aligned-day-of-week-in-year
@@ -402,7 +443,7 @@ via the `java-time.repl` ns:
402443 ...)
403444```
404445
405- ``` clj
446+ ``` clojure
406447(java-time.repl/show-units )
407448=> (:centuries
408449 :days
@@ -415,7 +456,7 @@ via the `java-time.repl` ns:
415456
416457You can obtain any field/unit like this:
417458
418- ``` clj
459+ ``` clojure
419460(field :year )
420461=> #object[java.time.temporal.ChronoField " Year" ]
421462
@@ -428,7 +469,7 @@ You can obtain any field/unit like this:
428469
429470You can obtain all of the fields/units of the temporal entity:
430471
431- ``` clj
472+ ``` clojure
432473(fields (local-date ))
433474=> {:proleptic-month #object[java.time.temporal.ChronoField ...}
434475
@@ -441,7 +482,7 @@ By themselves the fields and units aren't very interesting. You can get the
441482range of valid values for a field and a duration between two dates, but that's
442483about it:
443484
444- ```clj
485+ ```clojure
445486(range (field :year ))
446487=> #object[java.time.temporal.ValueRange " -999999999 - 999999999" ]
447488
@@ -458,7 +499,7 @@ are reasons for that which I feel are only valid in a statically-typed API like
458499Java's. In Clojure, properties allow expressing time entity modifications and
459500queries uniformly across all of the entity types.
460501
461- ```clj
502+ ```clojure
462503(def prop (property (local-date 2015 2 28 ) :day-of-month ))
463504=> #java_time.temporal.TemporalFieldProperty{...}
464505
@@ -496,7 +537,7 @@ Hopefully, the performance issue will be resolved in the future...
496537
497538You can play with the conversion graph using the following helpers:
498539
499- ```clj
540+ ```clojure
500541(java-time.repl/show-path org.joda.time.DateTime java.time.OffsetTime)
501542=> {:cost 2.0 ,
502543 :path [[#<java_time.graph.Types@15e43 c24 [org.joda.time.DateTime]>
0 commit comments