Package: effect
Module: DateTime
Pattern match on a DateTime to handle Utc and Zoned cases differently.
Example (Pattern matching DateTime variants)
import { DateTime } from "effect"
const dt1 = DateTime.makeUnsafe("2024-01-01T12:00:00Z") // Utc
const dt2 = DateTime.makeZonedUnsafe("2024-06-15T14:30:00Z", {
timeZone: "Europe/London"
}) // Zoned
const result1 = DateTime.match(dt1, {
onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`,
onZoned: (zoned) => `Zoned: ${DateTime.formatIsoZoned(zoned)}`
})
const result2 = DateTime.match(dt2, {
onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`,
onZoned: (zoned) => `Zoned: ${DateTime.formatIsoZoned(zoned)}`
})
console.log(result1) // "UTC: 2024-01-01T12:00:00.000Z"
console.log(result2) // "Zoned: 2024-06-15T15:30:00.000+01:00[Europe/London]"
Signature
declare const match: { <A, B>(options: { readonly onUtc: (_: Utc) => A; readonly onZoned: (_: Zoned) => B; }): (self: DateTime) => A | B; <A, B>(self: DateTime, options: { readonly onUtc: (_: Utc) => A; readonly onZoned: (_: Zoned) => B; }): A | B; }
Since v3.6.0