- datetime.timedelta representing the period of time. Otherwise
- maybe raise an ArgumentTypeError or potentially just treat the
- time window as zero in length.
+ datetime.timedelta representing the duration described.
+ This uses `datetime_utils.parse_duration` to parse durations
+ and expects data such as:
+
+ - 15 days, 3 hours, 15 minutes
+ - 15 days 3 hours 15 minutes
+ - 15d 3h 15m
+ - 15d3h5m
+ - 3m 2s
+ - 1000s
+
+ If the duration is not parsable, raise an ArgumentTypeError.
+
+ Args:
+ txt: data passed to a commandline arg expecting a duration.
+
+ Returns:
+ The datetime.timedelta described by txt or raises ArgumentTypeError
+ on error.
+
+ Sample usage::
+
+ cfg.add_argument(
+ '--ip_cache_max_staleness',
+ type=argparse_utils.valid_duration,
+ default=datetime.timedelta(seconds=60 * 60 * 4),
+ metavar='DURATION',
+ help='Max acceptable age of the IP address cache'
+ )
+
+ >>> valid_duration('15d3h5m')
+ datetime.timedelta(days=15, seconds=11100)
+
+ >>> valid_duration('15 days 3 hours 5 min')
+ datetime.timedelta(days=15, seconds=11100)