Skip to content

DurationFromString #6005

@Tiernan8r

Description

@Tiernan8r

What is the problem this feature would solve?

Currently when defining a schema to decode an input into a Duration, the options are the define the input using units of milllis/nanos. This input is neither convenient for large durations, nor very human readable.

We have a usecase where define a set of environment configurations to be parsed via a schema. Some fields we would like to be transformed to Duration, but are on the order of years. Defining this value as milliseconds makes it unclear what the actual year value is without an explanatory comment.

Additionally, an encode/decode cycle of a Duration object of:
input (string) -> decodeUnknown() -> format() -> produces a string output that is not re-parseable by decodeUnknown as the sub-units are not a match against the regex used to decode from string.

What is the feature you are proposing to solve the problem?

A DurationFromString schema transformation would allow input to be defined like "1 year 6 months" to be correctly coerced into a Duration value, instead of having to at the moment define the input as 47,304,000,000 (millis)

What alternatives have you considered?

We have implemented an in house DurationFromString transformation to solve our use case, but this could definitely be brought into the package for the benefit of the community at large

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions