human-time
A command-line tool for converting time durations to human-readable formats, built using the human-time crate.
Installation
Usage
Options
-u, --unit <UNIT>: Specify the unit of the time duration (milli, micro). If not specified, the tool will first check thedefault_time_value_unitsin the config file. If no config file exists or it doesn't specify a unit, it defaults to seconds.-c, --config: Specify if there is a config file. (See Configuration section for details on creating a config file.)
Examples
-
Convert 120 seconds to human-readable format:
Output:
2m -
Convert 500 milliseconds to human-readable format:
Output:
1s,500ms -
Convert 7200 seconds using a config file:
(See Configuration section for details on creating a config file.)
-
Reading from stdin:
|Output:
1h
Configuration
The human-time tool supports a configuration file named human-time.toml. It can be placed in either of the following locations:
- The same directory as the
human-timeexecutable. - Your home directory.
If a config file is found, the tool will use it to customize the output format and units. If no config file is found, default values are used.
human-time.toml Example
= "seconds" # Default unit if -u is not provided
[]
= "{} {}" # Format string for each time unit. Must contain exactly two "{}" placeholders. The first is for the time value, the second for the unit.
= ", " # Delimiter between time units when multiple units are displayed
[]
= "day(s)"
= "hour(s)"
= "minute(s)"
= "second(s)"
= "millisecond(s)"
= "microsecond(s)"
Configuration Options
default_time_value_units: The default unit to use if the-uor--unitoption is not provided on the command line. Valid values are "seconds", "milliseconds", and "microseconds".formatting.format: The format string used to display each time unit. It must contain exactly two{}placeholders. The first{}is replaced with the numeric time value, and the second{}is replaced with the unit string.formatting.delimiter_text: The string used to separate multiple time units when the duration is expressed in more than one unit (e.g., "1 hour, 30 minutes").units: A table of unit strings. Singular/plural forms are automatically handled based on the time value if "(s)" is included (e.g., "second(s)").
Input from Stdin
If no TIME_DURATION is provided as a command-line argument, human-time will attempt to read the duration from standard input (stdin). This allows you to pipe values to the command.
Building from Source
If you want to build human-time from source, you'll need to have Rust and Cargo installed.
- Clone the repository.
- Navigate to the project directory.
- Run
cargo build.
The executable will be located in the target/debug directory.