Hyperlinkv0.8.0-beta.28

SchemaTransformation

SchemaTransformation.timeZoneNamedFromStringconsteffect/SchemaTransformation.ts:1742
Transformation<DateTime.TimeZone.Named, string, never, never>

Decodes an IANA time-zone identifier string into a DateTime.TimeZone.Named and encodes a named time zone back to its id.

When to use

Use when you need a schema transformation to accept only IANA time-zone identifier strings and produce DateTime.TimeZone.Named values.

Details

Decode fails with InvalidValue when the string is not a valid IANA time-zone identifier.

transformingtimeZoneFromString
export const timeZoneNamedFromString: Transformation<DateTime.TimeZone.Named, string> = transformOrFail<
  DateTime.TimeZone.Named,
  string
>({
  decode: (s) => {
    return Option.match(DateTime.zoneMakeNamed(s), {
      onNone: () =>
        Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: `Invalid IANA time zone: ${s}` })),
      onSome: Effect.succeed
    })
  },
  encode: (tz) => Effect.succeed(tz.id)
})
Referenced by 2 symbols