Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8030864

Add an efficient getDateTimeMillis method to java.time

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b114

      Description

      Add an efficient/fast/garbage free getDateTimeMillis method.

      That converts to epoch time without creating garbage. There doesn't seem to be an equivalent garbage free method on the new API, and this looks like an oversight.

      Conversion to epoch is important and doing it efficiently was a core reason many where using JodaTime. It would be a shame to lose it.

        Issue Links

          Activity

          Hide
          ntv Nadeesh Tv added a comment -
          Stephen/Roger
          Some methods in IsoChronlogy like
          date(Era era, int yearOfEra, int month, int dayOfMonth)
          dateYearDay(Era era, int yearOfEra, int dayOfYear)
          prolepticYear(Era era, int yearOfEra) accepting Era as a parameter . Can we change it to more concrete IsoEra?

          Even though it may not give much improvement in performance atleast we could avoid the unnecessary instance check in prolepticYear()


          Can I use IsoEra as parameter in Isochronology.epochSecond(IsoEra, int, int, int, int, int, int, ZoneOffset) instead of Era?
          Show
          ntv Nadeesh Tv added a comment - Stephen/Roger Some methods in IsoChronlogy like date(Era era, int yearOfEra, int month, int dayOfMonth) dateYearDay(Era era, int yearOfEra, int dayOfYear) prolepticYear(Era era, int yearOfEra) accepting Era as a parameter . Can we change it to more concrete IsoEra? Even though it may not give much improvement in performance atleast we could avoid the unnecessary instance check in prolepticYear() Can I use IsoEra as parameter in Isochronology.epochSecond(IsoEra, int, int, int, int, int, int, ZoneOffset) instead of Era?
          Hide
          scolebourne Stephen Colebourne added a comment -
          Two new default methods are on `Chronology`, so `Era` is the correct input:

          // untested, but probably close to correct, may need to use Math.addExact/multiplyExact
          public default long epochSecond(Era era, int year, int month, int dayOfMonth, int hour, int minute, int second, ZoneOffset offset) {
            long epochDay = IsoChronology.INSTANCE.date(era, year, month, dayOfMonth).toEpochDay();
            long time = (((hour * 60) + minute) * 60) + second;
            return epochDay * 86400 + time + offset.getTotalSeconds();
          }
          public default long epochSecond(int, int, int, int, int, int, ZoneOffset) {
            // similar to above
          }

          This default implementation will do for all calendar systems except IsoChronology, where the default method should be overridden to avoid creating a LocalDate on the first line.
          Show
          scolebourne Stephen Colebourne added a comment - Two new default methods are on `Chronology`, so `Era` is the correct input: // untested, but probably close to correct, may need to use Math.addExact/multiplyExact public default long epochSecond(Era era, int year, int month, int dayOfMonth, int hour, int minute, int second, ZoneOffset offset) {   long epochDay = IsoChronology.INSTANCE.date(era, year, month, dayOfMonth).toEpochDay();   long time = (((hour * 60) + minute) * 60) + second;   return epochDay * 86400 + time + offset.getTotalSeconds(); } public default long epochSecond(int, int, int, int, int, int, ZoneOffset) {   // similar to above } This default implementation will do for all calendar systems except IsoChronology, where the default method should be overridden to avoid creating a LocalDate on the first line.
          Show
          ntv Nadeesh Tv added a comment - http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-March/039218.html
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/a738394080a3
          User: ntv
          Date: 2016-04-06 07:42:14 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/a738394080a3 User: ntv Date: 2016-04-06 07:42:14 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/a738394080a3
          User: lana
          Date: 2016-04-13 17:56:05 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/a738394080a3 User: lana Date: 2016-04-13 17:56:05 +0000

            People

            • Assignee:
              ntv Nadeesh Tv
              Reporter:
              rriggs Roger Riggs
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: