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.
This commit is contained in:
mccabe%netscape.com 2000-03-10 02:05:41 +00:00
Родитель 54eeb4f424
Коммит 98328c4bf4
2 изменённых файлов: 40 добавлений и 6 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}