masterzu / td.sh

Converting seconds to human readable time duration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

td.sh

Converting seconds to human readable time duration.

Installation

By default, to install to /usr/local, run:

$ make install

Or to /usr:

$ make install PREFIX=/usr

Or to your home:

$ make install PREFIX=$HOME

To uninstall, use uninstall target with PREFIX if supplied during installation.

Usage

The basic usage:

$ ./td.sh 123
2 minutes 3 seconds

You can source the script to have print_td function for better performance:

$ source td.sh
$ print_td 123
2 minutes 3 seconds
$ ./td.sh 1 2 60 61
1 second
2 seconds
1 minute
1 minute 1 second
$ ./td.sh -p -P 1 2 60 61
 1 second 
 2 seconds
 1 minute 
 1 minute   1 second 
$ ./td.sh -p -P -a 1 2 60 61
 0 days  0 hours  0 minutes  1 second 
 0 days  0 hours  0 minutes  2 seconds
 0 days  0 hours  1 minute   0 seconds
 0 days  0 hours  1 minute   1 second 

Options

-a     prints all number even they are zeros.
-p[X]  padding for numbers. 'X' is the padding character, default is ' '.
-P     padding for unit strings.
  • -a will prints all numbers and units even the numbers are zeros.
  • -p prints out like 1 second or -p0 for 01 second or 07 seconds.
  • -P prints out like 1 minute 12 seconds, note there is additional space after minute.

Tests

There is a script named td-test.sh for testing, you can also run make test.

Links

License

This project is licensed under the MIT License.

Copyright (c) 2010, 2012 Yu-Jie Lin

About

Converting seconds to human readable time duration.

License:MIT License