Skip to content

Commit

Permalink
minor optimization and fix daylightsavingtime handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri authored and gbrail committed Jan 27, 2022
1 parent 22a79b4 commit 4eef449
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/org/mozilla/javascript/NativeDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,8 @@ private static double LocalTime(Context cx, double t) {
}

private static double internalUTC(Context cx, double t) {
double LocalTZA = cx.getTimeZone().getRawOffset();
return t - LocalTZA - DaylightSavingTA(cx, t - LocalTZA);
double local = t - cx.getTimeZone().getRawOffset();
return local - DaylightSavingTA(cx, local);
}

private static int HourFromTime(double t) {
Expand Down Expand Up @@ -1070,7 +1070,7 @@ private static double parseISOString(Context cx, String s) {

// browsers doing this now
if (timeSpecified) {
date -= cx.getTimeZone().getOffset((long) date);
date -= cx.getTimeZone().getRawOffset() + DaylightSavingTA(cx, date);
}
} else {
date -= (tzhour * 60 + tzmin) * msPerMinute * tzmod;
Expand Down
16 changes: 16 additions & 0 deletions testsrc/org/mozilla/javascript/tests/es6/NativeDateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ public void ctorDateTimeBerlin() {
});
}

@Test
public void ctorDateTimeBerlinDaylightSavingTime() {
String js = "new Date('2021-07-18T22:23').toISOString()";

Utils.runWithAllOptimizationLevels(
cx -> {
final Scriptable scope = cx.initStandardObjects();
cx.setLanguageVersion(Context.VERSION_ES6);
cx.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));

final Object res = cx.evaluateString(scope, js, "test.js", 0, null);
assertEquals("2021-07-18T20:23:00.000Z", res);
return null;
});
}

@Test
public void ctorDateTimeNewYork() {
String js = "new Date('2021-12-18T22:23').toISOString()";
Expand Down

0 comments on commit 4eef449

Please sign in to comment.