Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement human-readable durations in the config #4294

Open
0x009922 opened this issue Feb 18, 2024 · 2 comments
Open

Implement human-readable durations in the config #4294

0x009922 opened this issue Feb 18, 2024 · 2 comments
Labels
config-changes Changes in configuration and start up of the Iroha Enhancement New feature or request good first issue Good for newcomers iroha2-dev The re-implementation of a BFT hyperledger in RUST question Further information is requested UI Something about the interface

Comments

@0x009922
Copy link
Contributor

Description

Enhance HumanDuration type to actually parse a human-readable string:

/// [`Duration`], but can parse a human-readable string.
/// TODO: currently deserializes just as [`Duration`]
#[serde_with::serde_as]
#[derive(Debug, Copy, Clone, Deserialize, Serialize, Ord, PartialOrd, Eq, PartialEq)]
pub struct HumanDuration(#[serde_as(as = "serde_with::DurationMilliSeconds")] pub Duration);

Specification

Here is an excerpt from the configuration reference draft:

Duration is specified as a human-readable string:

value1 = "1sec"
value2 = "1hour 12min 5s"
value3 = "2years 2min 12us"
value4 = "550ms"

The duration string is a concatenation of time spans. Each time span is an
integer number and a suffix. Supported suffixes:

  • nsec, ns — nanoseconds
  • usec, us — microseconds
  • msec, ms — milliseconds
  • seconds, second, sec, s
  • minutes, minute, min, m
  • hours, hour, hr, h
  • days, day, d
  • weeks, week, w
  • months, month, M — defined as $30.44$ days
  • years, year, y — defined as $365.25$ days

I used humantime crate for reference. Maybe it can be used as is. Otherwise, it is straighforward (and quite interesting!) to write our own parser with something like winnow.

@0x009922 0x009922 added Enhancement New feature or request good first issue Good for newcomers iroha2-dev The re-implementation of a BFT hyperledger in RUST config-changes Changes in configuration and start up of the Iroha UI Something about the interface labels Feb 18, 2024
@mversic mversic added the question Further information is requested label Feb 19, 2024
@mversic
Copy link
Contributor

mversic commented Feb 19, 2024

as discussed here I'm not sure we want to complicate config files. Simple fixed suffix on the field name should suffice IMO. We need to discuss this before proceeding

@0x009922
Copy link
Contributor Author

There was a discussion in favor of human-readable strings here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config-changes Changes in configuration and start up of the Iroha Enhancement New feature or request good first issue Good for newcomers iroha2-dev The re-implementation of a BFT hyperledger in RUST question Further information is requested UI Something about the interface
Projects
Status: Roadmap
Development

No branches or pull requests

2 participants