effect-io-ai

Package: effect
Module: DateTime

DateTime.makeUnsafe

Create a DateTime from supported input values.

When to use

Use when creating a DateTime from trusted input and construction failures should throw an IllegalArgumentError instead of returning Option.none.

Details

Example (Creating DateTime values unsafely)

import { DateTime } from "effect"

// from Date
const fromDate = DateTime.makeUnsafe(new Date("2024-01-01T12:00:00Z"))
console.log(DateTime.formatIso(fromDate)) // "2024-01-01T12:00:00.000Z"

// from parts
const fromParts = DateTime.makeUnsafe({ year: 2024 })
console.log(DateTime.formatIso(fromParts)) // "2024-01-01T00:00:00.000Z"

// from string
const fromString = DateTime.makeUnsafe("2024-01-01")
console.log(DateTime.formatIso(fromString)) // "2024-01-01T00:00:00.000Z"

Signature

declare const makeUnsafe: <A extends DateTime.Input>(input: A) => DateTime.PreserveZone<A>

Source

Since v4.0.0