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

Issue with date.setFullYear when time other than midnight

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u25, 9
    • core-libs
    • b37
    • x86_64
    • windows_7

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

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        There is a discrepancy between the Java 8 Nashorn implementation of setFullYear and other implementations. If the time is set on a Date object when calling setFullYear the new Date is calculated to be one day less than if the date is set to midnight (00:00:00:00) and is also one day less than the Rhino engine used in Java 7.

        REGRESSION. Last worked in version 7u45

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Create a date with the time set e.g. new Date("January 01, 1950 00:00:01");
        call setFullYear(1960) on the date
        the date is now: Thu Dec 31 1959 00:00:01 GMT+0000 (GMT) rather than
        Fri Jan 01 1960 00:00:01 GMT-0000 (GMT)

        This was noticed in regression testing of moving some code from Java 7 to Java 8. (Rhino returns the expected result, Nashorn returns the actual).


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Before: Sun Jan 01 1950 00:00:00 GMT-0000 (GMT)
        After: Fri Jan 01 1960 00:00:00 GMT-0000 (GMT)
        Before: Sun Jan 01 1950 00:00:01 GMT-0000 (GMT)
        After: Fri Jan 01 1960 00:00:01 GMT-0000 (GMT)

        This was produced using Java 7 Rhino.

        ACTUAL -
        Before: Sun Jan 01 1950 00:00:00 GMT+0000 (GMT)
        After: Fri Jan 01 1960 00:00:00 GMT+0000 (GMT)
        Before: Sun Jan 01 1950 00:00:01 GMT+0000 (GMT)
        After: Thu Dec 31 1959 00:00:01 GMT+0000 (GMT)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        print("version: " +java.lang.System.getProperty("java.version"));
        var date1 = new Date("January 01, 1950 00:00:00");
        print("Before: "+date1);
        date1.setFullYear(1960);
        print("After: "+date1);

        var date2 = new Date("January 01, 1950 00:00:01");
        print("Before: "+date2);
        date2.setFullYear(1960);
        print("After: "+date2);
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        The time element was actually unnecessary for our usage so we were able to amend the code to set the date to midnight before calling setFullYear()



              sundar Sundararajan Athijegannathan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: