Posts Tagged time

parseInt gotchas

Debugging an application today before launch I noticed a problem where it seemed to be parsing a specific time value (0900) incorrectly as (12:00 AM or ‘0000’). ┬áDuring my search I ran across this oddity with the parseInt function of Javascript.

Apparently parseInt can also work with different base notations so it’s a good idea to specify base 10 in the manner parseInt(val,10) just to be safe if you are passing it numbers (such as time values) that may start with a zero and you don’t want invalid octal numbers (like 09) parsing to zero.


Tags: , ,

Web browsers and time

Today I had an interesting task of figuring out why a piece of code I’d written a few weeks ago for autosaving user changes wasn’t being called as uniformly as we’d thought.

That is, on IE6 and FF, we were seeing a particular piece of code take almost twice as long to execute as it ought because (as we later found out) timings in javascript can’t be trusted.

So, if you need something to run on time, at regular intervals; use a polling pattern instead of relying on the usual javascript methods.

Tags: , ,