I was in need of timer to mark an important decision; I did what most of us would do - search on the internet. I found quite a few of them, but I didn’t like any of them. Some of them were unnecessarily complicated; a couple of others weren’t easily understandable; most of them were using approximation (esp. for months and years).
My requirement was that the timer should be simple and which counts time exactly the same way we humans do. So I decided to write one myself. Before going into the details, I wanted it for my homepage.
This script is very simple; it takes a date to count the time from, an ID to put the timer and a message to append to the timer. It is also possible to have more than one timer on a page - check the demo link given at the end of this post.
Call me paranoid; I like bug-free code, who wouldn’t?
If you noticed the version, it is v2.0?! It is. Initially I had slightly different idea to update the counter every second. Though it seemed to work fine, I could think of a case where it would break. numOfDays is set initially when the timer starts. If the browser is kept open for a long time (really long time!), numOfDays could become invalid. This could have been fixed easily in v1.0 itself, but I rewrote it to make it even simpler. Have a look at v1.0 below if you want to.
I have created a page to demonstrate the timer - demo (I have included another kind of timer in the middle of the page where each unit is independent of other; this uses approximation to calculate months/years)
In case of any issues/doubts/suggestions or you just want to appreciate :o), feel free to leave a comment.