src/jdk/nashorn/internal/objects/NativeDate.java

Print this page

        

*** 517,527 **** * @return time zone offset or NaN if N/A */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getTimezoneOffset(final Object self) { final NativeDate nd = getNativeDate(self); ! if (nd != null) { final long msec = (long) nd.getTime(); return - nd.getTimeZone().getOffset(msec) / msPerMinute; } return Double.NaN; } --- 517,527 ---- * @return time zone offset or NaN if N/A */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object getTimezoneOffset(final Object self) { final NativeDate nd = getNativeDate(self); ! if (nd != null && nd.isValidDate()) { final long msec = (long) nd.getTime(); return - nd.getTimeZone().getOffset(msec) / msPerMinute; } return Double.NaN; }
*** 533,544 **** * @param time time * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object setTime(final Object self, final Object time) { - final double num = timeClip(JSType.toNumber(time)); final NativeDate nd = getNativeDate(self); nd.setTime(num); return num; } /** --- 533,544 ---- * @param time time * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object setTime(final Object self, final Object time) { final NativeDate nd = getNativeDate(self); + final double num = timeClip(JSType.toNumber(time)); nd.setTime(num); return num; } /**
*** 549,561 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object setMilliseconds(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, MILLISECOND, args, true); - } return nd.getTime(); } /** * ECMA 15.9.5.29 Date.prototype.setUTCMilliseconds (ms) --- 549,559 ----
*** 565,577 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object setUTCMilliseconds(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, MILLISECOND, args, false); - } return nd.getTime(); } /** * ECMA 15.9.5.30 Date.prototype.setSeconds (sec [, ms ] ) --- 563,573 ----
*** 581,593 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) public static Object setSeconds(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, SECOND, args, true); - } return nd.getTime(); } /** * ECMA 15.9.5.31 Date.prototype.setUTCSeconds (sec [, ms ] ) --- 577,587 ----
*** 597,609 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) public static Object setUTCSeconds(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, SECOND, args, false); - } return nd.getTime(); } /** * ECMA 15.9.5.32 Date.prototype.setMinutes (min [, sec [, ms ] ] ) --- 591,601 ----
*** 613,625 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3) public static Object setMinutes(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, MINUTE, args, true); - } return nd.getTime(); } /** * ECMA 15.9.5.33 Date.prototype.setUTCMinutes (min [, sec [, ms ] ] ) --- 605,615 ----
*** 629,641 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3) public static Object setUTCMinutes(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, MINUTE, args, false); - } return nd.getTime(); } /** * ECMA 15.9.5.34 Date.prototype.setHours (hour [, min [, sec [, ms ] ] ] ) --- 619,629 ----
*** 645,657 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4) public static Object setHours(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, HOUR, args, true); - } return nd.getTime(); } /** * ECMA 15.9.5.35 Date.prototype.setUTCHours (hour [, min [, sec [, ms ] ] ] ) --- 633,643 ----
*** 661,673 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4) public static Object setUTCHours(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, HOUR, args, false); - } return nd.getTime(); } /** * ECMA 15.9.5.36 Date.prototype.setDate (date) --- 647,657 ----
*** 677,689 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object setDate(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, DAY, args, true); - } return nd.getTime(); } /** * ECMA 15.9.5.37 Date.prototype.setUTCDate (date) --- 661,671 ----
*** 693,705 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object setUTCDate(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, DAY, args, false); - } return nd.getTime(); } /** * ECMA 15.9.5.38 Date.prototype.setMonth (month [, date ] ) --- 675,685 ----
*** 709,721 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) public static Object setMonth(final Object self, final Object... args) { final NativeDate nd = getNativeDate(self); - if (nd.isValidDate()) { setFields(nd, MONTH, args, true); - } return nd.getTime(); } /** * ECMA 15.9.5.39 Date.prototype.setUTCMonth (month [, date ] ) --- 689,699 ----
*** 725,737 **** * @return time */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2) public static Object setUTCMonth(final Object self, final Object... args) { final NativeDate nd = ensureNativeDate(self); - if (nd.isValidDate()) { setFields(nd, MONTH, args, false); - } return nd.getTime(); } /** * ECMA 15.9.5.40 Date.prototype.setFullYear (year [, month [, date ] ] ) --- 703,713 ----
*** 745,755 **** --- 721,735 ---- final NativeDate nd = ensureNativeDate(self); if (nd.isValidDate()) { setFields(nd, YEAR, args, true); } else { final double[] d = convertArgs(args, 0, YEAR, YEAR, 3); + if (d != null) { nd.setTime(timeClip(utc(makeDate(makeDay(d[0], d[1], d[2]), 0), nd.getTimeZone()))); + } else { + nd.setTime(NaN); + } } return nd.getTime(); } /**
*** 780,804 **** */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object setYear(final Object self, final Object year) { final NativeDate nd = getNativeDate(self); if (isNaN(nd.getTime())) { ! return null; } final double yearNum = JSType.toNumber(year); if (isNaN(yearNum)) { nd.setTime(NaN); ! return nd; } int yearInt = JSType.toInteger(yearNum); if (0 <= yearInt && yearInt <= 99) { yearInt += 1900; } setFields(nd, YEAR, new Object[] {yearInt}, true); ! return nd; } /** * ECMA 15.9.5.42 Date.prototype.toUTCString ( ) * --- 760,784 ---- */ @Function(attributes = Attribute.NOT_ENUMERABLE) public static Object setYear(final Object self, final Object year) { final NativeDate nd = getNativeDate(self); if (isNaN(nd.getTime())) { ! nd.setTime(utc(0, nd.getTimeZone())); } final double yearNum = JSType.toNumber(year); if (isNaN(yearNum)) { nd.setTime(NaN); ! return nd.getTime(); } int yearInt = JSType.toInteger(yearNum); if (0 <= yearInt && yearInt <= 99) { yearInt += 1900; } setFields(nd, YEAR, new Object[] {yearInt}, true); ! return nd.getTime(); } /** * ECMA 15.9.5.42 Date.prototype.toUTCString ( ) *
*** 1296,1305 **** --- 1276,1289 ---- length = 4; } final double time = local ? nd.getLocalTime() : nd.getTime(); final double d[] = convertArgs(args, time, fieldId, start, length); + if (! nd.isValidDate()) { + return; + } + double newTime; if (d == null) { newTime = NaN; } else { if (start == YEAR) {