Skip to content

feat: add unit after duration parameter in configuration file

Félix Olart requested to merge feature/config-file-duration-type into master

Overview

This MR aims at supporting units along with the value for a duration parameter in the configuration file.

  • Supported units: ms, s, min, h, d, m, y.
  • Syntax is: <value>[ms|s|min|h|d|m|y]. Examples: "35", "42ms", "35d".
  • No combinations allowed.
  • Times are converted and returned in ms using the read() method.

TODO

Write unit tests

  • Current configuration file is still read correctly (without indicating any unit).
  • The value is correctly read when using a valid unit (ms, s, min, h, d, m, y).
  • An exception is thrown when the parameter is not well formatted.
    • "42unknowunit"
    • "s42" or "min42"
    • "42min12s"
    • "42.0"
    • "42.min"
    • "42.0s"
    • "ms42"
    • "ms"
    • "42ms text"

Usage example

  • Before this MR
# Duration of the validity of the credentials added to the cache.
# Default: 1800
cache-expire=1800
  • After this MR
# Duration of the validity of the credentials added to the cache.
# Default: 1800
# Unit: second
cache-expire=1800s
# or
cache-expire=1800000ms
# or
cache-expire=30min

Details

We decided to implement three duration types in order to maintain compatibility with current and older configuration files (which does not indicate units after the value). Indeed, all duration values are currently indicated in milliseconds, seconds or minutes.

Edited by Félix Olart

Merge request reports