Package: effect
Module: SchemaTransformation
Decodes a string into a Duration and encodes a Duration back to a
parseable string.
When to use
Use when you need a schema transformation to parse human-readable duration strings from APIs, config, or user input.
Details
Decoding accepts any string that Duration.fromInput can parse, including
"Infinity" and "-Infinity". Encoding returns String(duration),
producing strings such as "2000 millis" or "10 nanos" that round-trip
through the parser.
Example (Converting a string to a Duration)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.String.pipe(
Schema.decodeTo(Schema.Duration, SchemaTransformation.durationFromString)
)
See
durationFromNanosdurationFromMillisSignature
declare const durationFromString: Transformation<Duration.Duration, string, never, never>
Since v4.0.0