From 98328c4bf40281c7e783e78e6fa124a7839e5419 Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Fri, 10 Mar 2000 02:05:41 +0000 Subject: [PATCH] Replace some ternary expressions step += (InLeapYear(t) ? 29 : 28); with the form if (InLeapYear(t)) step += 29; else step += 28; to work around an apparent JRE bug in which the code always returns 28. --- .../org/mozilla/javascript/NativeDate.java | 23 ++++++++++++++++--- .../org/mozilla/javascript/NativeDate.java | 23 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/js/rhino/org/mozilla/javascript/NativeDate.java b/js/rhino/org/mozilla/javascript/NativeDate.java index a48d9a15326..9e2d5408829 100644 --- a/js/rhino/org/mozilla/javascript/NativeDate.java +++ b/js/rhino/org/mozilla/javascript/NativeDate.java @@ -222,7 +222,14 @@ public class NativeDate extends ScriptableObject { if (d < (step = 31)) return 0; - step += (InLeapYear(t) ? 29 : 28); + + // Originally coded as step += (InLeapYear(t) ? 29 : 28); + // but some jits always returned 28! + if (InLeapYear(t)) + step += 29; + else + step += 28; + if (d < step) return 1; if (d < (step += 31)) @@ -250,11 +257,17 @@ public class NativeDate extends ScriptableObject { int d, step, next; d = DayWithinYear(t); - if (d <= (next = 30)) return d + 1; step = next; - next += (InLeapYear(t) ? 29 : 28); + + // Originally coded as next += (InLeapYear(t) ? 29 : 28); + // but some jits always returned 28! + if (InLeapYear(t)) + next += 29; + else + next += 28; + if (d <= next) return d - step; step = next; @@ -285,6 +298,10 @@ public class NativeDate extends ScriptableObject { if (d <= (next += 30)) return d - step; step = next; + + System.err.println("step is " + step); + System.err.println("result is " + (d - step)); + return d - step; } diff --git a/js/rhino/src/org/mozilla/javascript/NativeDate.java b/js/rhino/src/org/mozilla/javascript/NativeDate.java index a48d9a15326..9e2d5408829 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeDate.java +++ b/js/rhino/src/org/mozilla/javascript/NativeDate.java @@ -222,7 +222,14 @@ public class NativeDate extends ScriptableObject { if (d < (step = 31)) return 0; - step += (InLeapYear(t) ? 29 : 28); + + // Originally coded as step += (InLeapYear(t) ? 29 : 28); + // but some jits always returned 28! + if (InLeapYear(t)) + step += 29; + else + step += 28; + if (d < step) return 1; if (d < (step += 31)) @@ -250,11 +257,17 @@ public class NativeDate extends ScriptableObject { int d, step, next; d = DayWithinYear(t); - if (d <= (next = 30)) return d + 1; step = next; - next += (InLeapYear(t) ? 29 : 28); + + // Originally coded as next += (InLeapYear(t) ? 29 : 28); + // but some jits always returned 28! + if (InLeapYear(t)) + next += 29; + else + next += 28; + if (d <= next) return d - step; step = next; @@ -285,6 +298,10 @@ public class NativeDate extends ScriptableObject { if (d <= (next += 30)) return d - step; step = next; + + System.err.println("step is " + step); + System.err.println("result is " + (d - step)); + return d - step; }