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

Webview - Bug in JavaScript Date() constructor after Feb 28 2034

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • 9
    • 8u66, 9
    • javafx
    • web
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.10586]
      Linux 3.12.11-201.fc19.i686 #1 SMP Fri Feb 14 19:35:05 UTC 2014 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The built-in parser of the JavaScript Date() object in the JavaFX webview component returns a wrong date if used with a date after February 28 2034.

      Example:
      new Date('February 28, 2034 10:00:00').toUTCString() --> Tue, 28 Feb 2034 10:00:00 GMT (correct)
      new Date('March 1, 2034 10:00:00').toUTCString() --> Tue, 28 Feb 2034 10:00:00 GMT (incorrect)

      For all dates after February 28 2034, one day is missing.

      It works properly if the Date() constructor with the components is used:
      new Date(2034, 1, 28, 10, 0, 0).toUTCString() --> Tue, 28 Feb 2034 10:00:00 GMT (correct)
      new Date(2034, 2, 1, 10, 0, 0).toUTCString() --> Wed, 01 Mar 2034 10:00:00 GMT (correct)

      This bug is applicable in both Windows and Linux, both x86 and x64 versions of the JRE.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached web page within a JavaFX WebView.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      <!DOCTYPE html>
      <html>

      <head>
      <script type="text/javascript">

      // string values for the months
      var months = [ null, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];

      // date values to show
      var dates = [
          { year: 2016, month: 1, day: 6, hour: 10, minute: 0, second: 0 },
          { year: 2034, month: 1, day: 6, hour: 10, minute: 0, second: 0 },
          { year: 2034, month: 2, day: 28, hour: 10, minute: 0, second: 0 },
          { year: 2034, month: 3, day: 1, hour: 10, minute: 0, second: 0 },
          { year: 2034, month: 12, day: 31, hour: 23, minute: 59, second: 59 }
      ];

      // function to return a date/time string (to be passed to new Date()) from our date structure
      function getParseString(d) {
          return months[d.month] + ' ' + d.day + ', ' + d.year + ' ' + d.hour + ':' + d.minute + ':' + d.second;
      }

      // function to get the components of the date as string
      function getComponentsString(d) {
          return '' + d.year + ', ' + (d.month - 1) + ', ' + d.day + ', ' + d.hour + ', ' + d.minute + ', ' + d.second;
      }

      // function to return a Date object from our date structure
      function getDateObject(d) {
          return new Date(d.year, d.month - 1, d.day, d.hour, d.minute, d.second);
      }

      </script>
      </head>

      <body>
      <table>
          <tr>
              <th>String to parse</th>
              <th>Parsed date</th>
              <th>Split components</th>
              <th>Regular date</th>
          </tr>
          <script type="text/javascript">
              var i;
              for (i = 0; i < dates.length; i++) {
                  var d = dates[i], s = getParseString(d), d1 = new Date(s), cs = getComponentsString(d), d2 = getDateObject(d);
                  document.write(' <tr>');
                  document.write(' <td>' + s + '</td>');
                  document.write(' <td>' + d1.toUTCString() + '</td>');
                  document.write(' <td>' + cs + '</td>');
                  document.write(' <td>' + d2.toUTCString() + '</td>');
                  document.write(' </tr>');
              }
          </script>
      </table>

      </body>
      </html>

      ---------- END SOURCE ----------

            ghb Guru Hb (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: