A few times I need to print out a human readable time, e.g. 3 minutes 5 seconds ago. I am not aware a very common tool to print out such text. So, I usually ended up with writing a short code to do such thing.
I decided to write one in Bash a couple of days ago, few hours ago, I wrote td.sh and td-test.sh.
$ ./td.sh 123 2 minutes 3 seconds $ source td.sh -s $ print_td 123 2 minutes 3 seconds
You can run it with seconds as argument, or source it and call print_td.
The test file shows more examples of outputs:
$ ./td-test.sh Passed: 0 => "0 seconds" Passed: 1 => "1 second" Passed: -1 => "1 second" Passed: 2 => "2 seconds" Passed: 60 => "1 minute" Passed: 61 => "1 minute 1 second" Passed: 3599 => "59 minutes 59 seconds" Passed: 3600 => "1 hour" Passed: 3601 => "1 hour 1 second" Passed: 3660 => "1 hour 1 minute" Passed: 3661 => "1 hour 1 minute 1 second" Passed: 86400 => "1 day" Passed: 172799 => "1 day 23 hours 59 minutes 59 seconds" Passed: 259199 => "2 days 23 hours 59 minutes 59 seconds" Passed: 31622401 => "366 days 1 second" 0 failures of 15 tests. 1868 conversions per second via function calls. 203 conversions per second via script executions.
td.sh would not use months, or years, because they are not clear if you want to know how many days exactly under some circumstances, though you probably wouldnt care. It ignores negative sign, its irrelevant for time duration. You will have to deal with that on you own. It doesnt show those are zeros except you give it 0.
Anyway, you can put this in your conky:
$ echo "$(./td.sh $(($(date +%s -d'Nov 25 18:00 2010') - $(date +%s)))) utill a yummy turkey on table..." 3 days 11 hours 6 minutes utill a yummy turkey on table...
0 comments:
Post a Comment