What you need to do to win this challenge is to write the shortest "timeago" script that outputs the number of decades, years, weeks, days, hours, minutes, and seconds between a given Unix timestamp and the time the script is run.
You must give the time difference in "lowest terms", e.g. 1 week
not 7 days
, 9 years
not 0 decades 9 years
. You also must use plural forms correctly, e.g. 1 day
not 1 days
.
Your script must be accurate to within plus or minus 1 second (so the exact second rounding method is unimportant).
Time Equivalency Table
1 decade = 10 years
1 year = 31536000 seconds (not technically correct but close enough)
1 week = 7 days
1 day = 24 hours
1 hour = 60 minutes
1 minute = 60 seconds
The output should be of the form
A decade(s) B year(s) C week(s) D day(s) E hour(s) F minute(s) G second(s)
where A...G
are all non-negative integers and the s
is only there for plurals.
Notes
- The timestamp will always be a time from the past. It may be negative.
- Input and output may be anything reasonable: stdin/stdout, function input and return value, etc.
- You may not use any tools that already do this. i.e. if your language has a
timesince(timestamp)
function built in you may not use that function.
I have vastly edited this to make it clearer in hopes to assuage the somewhat silly battle between new users with unclear questions and old users who require perfection. It was not a terrible question (though now it may be too similar to this).
Given that enough time is passed since the last answer, I declare Three If By Whiskey with its 177 bytes Ruby implementation the winner of this context!