How a single conversion runs
Three controls sit in a row: an Amount box (id tconvInput, holding 7 and refusing negatives), plus the two unit selects. Every one of the seven units, seconds through years, appears in both lists in a different order, so the page opens on Seconds to Hours. Typing in the amount or changing either select runs convertTime, which multiplies the amount by the source factor to reach seconds, then divides by the target factor, and the blue panel updates.
The factors it multiplies by
The constants are fixed in the script: s 1, min 60, h 3600, d 86400, wk 604800, mo 2592000 and yr 31536000. A month therefore means exactly 30 days and a year exactly 365 days, with no special handling for February or leap years.
A worked example
On load the page takes the default 7 seconds, keeps 7 after multiplying by the seconds factor, and divides by 3600 to get 0.0019444. The formatter pins the answer to four decimals, so the panel reads 0.0019 h. Switch the target to Days and 7 over 86400 rounds up to 0.0001, printed as 0.0001 d.
Where it stops
- A cleared or unparseable amount is silently converted to 0.
- Months of 30 days and years of 365 days drift against the real calendar.
- Answers above one billion switch to four-digit scientific notation, and ordinary results lose accuracy past four decimals.
- The unit appended to the number is the raw code, so hours read h and minutes read min.
Questions people ask
Why does my precise number show only four decimals?
Output is fixed to four places with trailing zeros removed; that is the whole display rule, so 7 seconds in hours can only ever print as 0.0019.
How many seconds is a month here?
2,592,000, which is 30 full days, matching the fixed constant every month conversion divides by.
What if I need calendar awareness
This page multiplies fixed constants, so date arithmetic belongs elsewhere: the Time Duration Calculator, the Unix Timestamp Converter and the Date Calculator all cope with months that vary in length.