timedelta Mode
In timedelta mode, timedelta values are generated. The format of the command is as follows:
randog timedelta [MINIMUM MAXIMUM] [--unit UNIT] [--iso | --fmt FORMAT] [common-options]
Arguments and Options
MINIMUM
(optional):the minimum value with the simple format; see also here. If not specified, the behavior is left to the specification of randtimedelta.
MAXIMUM
(optional):the maximum value with the simple format; see also here. If not specified, the behavior is left to the specification of randtimedelta.
--unit UNIT
(optional):the minimum unit of generated values with the simple format; see also here. If not specified, the behavior is left to the specification of randtimedelta.
--iso
(optional):if specified, it outputs generated object with ISO-8601 format.
--fmt FORMAT
(optional):if specified, it outputs generated object with the specified format; The format is specified in the format codes.
common-options
Examples
The simplest example is the following, which outputs a timedelta value.
randog timedelta
You can specify a range of values to be generated, as in the following example:
# generates a value between 1 day and 7 day
randog timedelta 1d 7d
If the minimum unit is not specified, it will be adjusted to the appropriate length. In many cases, it may be necessary to specify this manually as follows
# generates a value between 0 day and 1 day with minimum unit 1 second
randog timedelta 0 1d --unit 1s
Format: ISO-8601, etc.
By default, the output is in the simple format, but you can change the output format to the format specified in the format codes or ISO-8601 format by specifying options as follows:
# generates a value with ISO-8601 format
randog timedelta 0 1d --unit 1s --iso
# generates a value with the specified format (x days xx:xx:xx)
randog timedelta 0 7d --unit 1s --fmt '%D days %H:%M:%S'
# generates a value with the specified format (x:xx:xx)
randog timedelta 0 7d --unit 1s --fmt '%tH:%M:%S'
Repeatedly Generate
Most likely, you will not be satisfied with just one generated, so you will probably want to output multiple times as follows:
# Repeat 10 times
randog timedelta -r 10
# Generate list which contains 10 values
randog timedelta -L 10 --json --iso
Simple Format
In this mode, duration is represented in a proprietary format, such as 1h30m
or 1d2h3m4s5ms6us
.
This format expresses duration by concatenating one or more of the following elements:
Directive |
Meaning |
---|---|
|
X is number of days. For example, |
|
X is number of hours. For example, |
|
X is number of minutes. For example, |
|
X is number of seconds. For example, |
|
X is number of milliseconds. For example, |
|
X is number of microseconds. For example, |
|
Zero. It is same as
0d , 0h , 0s , and so on.In the case of zero, the unit is meaningless, so the notation without unit is also allowed.
|
Note
It is not possible to specify by months or years. This is because python’s timedelta does not manage units larger than days and cannot distinguish between a month and 30 days, for example.
Format codes
Python timedelta has no format codes defined, but in this mode, you can use proprietary format codes:
Directive |
Meaning |
Example |
---|---|---|
|
equals to |
0, 1, 2, … |
|
hours part (zero-padded to 2 digits) |
00, 01, …, 23 |
|
total duration in hours (rounded down) |
0, 1, 2, … |
|
minutes part (zero-padded to 2 digits) |
00, 01, …, 59 |
|
total duration in minutes (rounded down) |
0, 1, 2, … |
|
seconds part (zero-padded to 2 digits) |
00, 01, …, 59 |
|
total duration in seconds (rounded down) |
0, 1, 2, … |
|
decimal part in seconds (zero-padded to 6 digits) |
000000, 000001, …, 999999 |
Typically, the following formats are used:
%D %H:%M:%S
“140 hours” is represented as “5 20:00:00”
%tH:%M:%S
“140 hours” is represented as “140:00:00”
Note
It is not possible to specify by months or years. This is because python’s timedelta does not manage units larger than days and cannot distinguish between a month and 30 days, for example.