You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know why my program was receiving that input but YearFromTime(-6.77681005679532E19) causes an invite loop. Simple fix is changing mid, hi and lo variables to long. I guess the function can continue returning an int as result without changing or compromising current functionality and normal inputs.
The text was updated successfully, but these errors were encountered:
Thanks for finding this -- I agree it's a problem, because even when it's not a loop it can take a very very long time -- we need a better solution. If you know of any date/time parsing code we can re-use then that might help a lot.
I tried using the standard Java date-time parsing code here, but the problem is that ECMAScript has very very specific ideas of time which are not exactly the same as Java's.
(I also don't think that we want to include JODATime, because so far Rhino has no dependencies and adding one will greatly complicate other people's lives.)
Yes, 22 iterations (with int to long fix) are too much!
Maybe it's crazy but project Nashorn must implement the same specs. I love the ability of using interpreted mode of Rhino and ability to completely serialise an entire scope to disk. But sharing parts of code from Nashorn might help solving problems like this only once. For example Nashorn has this simple code (from its NativeDate.java)
// ECMA 15.9.1.3 Year Number
private static int yearFromTime(final double t) {
int y = (int) Math.floor(t / (msPerDay * 365.2425)) + 1970;
final double t2 = timeFromYear(y);
if (t2 > t) {
y--;
} else if (t2 + msPerDay * daysInYear(y) <= t) {
y++;
}
return y;
}
Not sure if it works in all cases but worth a try.
I don't know why my program was receiving that input but YearFromTime(-6.77681005679532E19) causes an invite loop. Simple fix is changing mid, hi and lo variables to long. I guess the function can continue returning an int as result without changing or compromising current functionality and normal inputs.
The text was updated successfully, but these errors were encountered: