Dan Anglin
0ad02e0af4
This commit adds a new parser for the internal time duration flag value (TimeDurationValue). Previously this used the parser from the time package from the standard library but this was limited to parsing units of time up to hours. The new parser allows users to specify duration in days, hours, minutes, seconds and a combination of the above. It is quite flexible in the way users format their string input. Additonal changes: - Added unit tests for the command-line parsing of the TimeDurationValue type. - Updated the unit tests for the BoolPtrValue type. - Updated documentation. PR: #55
24 lines
1 KiB
Markdown
24 lines
1 KiB
Markdown
# Tips and Tricks
|
|
|
|
## The time duration value
|
|
|
|
The time duration value is a custom [flag value](https://pkg.go.dev/flag#Value) that converts a string input into a duration of time.
|
|
A typical string input would be in the form of something like `"3 days, 12 hours and 39 minutes"`.
|
|
The value can convert units in days, hours, minutes and seconds.
|
|
|
|
To ensure that your string input is converted correctly there are simple rules to follow.
|
|
|
|
- The input must be wrapped in quotes.
|
|
- Use `day` or `days` to convert the number of days.
|
|
- Use `hour` or `hours` to convert the number of hours.
|
|
- Use `minute` or `minutes` to convert the number of minutes.
|
|
- Use `second` or `seconds` to convert the number of seconds.
|
|
- There must be at least one space between the number and the unit of time.<br>
|
|
E.g. `"7 days"` is valid, but `"7days"` is invalid.
|
|
|
|
### Example valid string inputs
|
|
|
|
- `"3 days"`
|
|
- `"6 hours, 45 minutes and 1 second"`
|
|
- `"1 day, 15 hours 31 minutes and 12 seconds"`
|
|
- `"(7 days) (1 hour) (21 minutes) (35 seconds)"`
|