Hyperlinkv0.8.0-beta.28

DateTime

DateTime.makeUnsafeconsteffect/DateTime.ts:656
<A extends DateTime.Input>(input: A): DateTime.PreserveZone<A>

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

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentError)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

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"
constructors
export const makeUnsafe: <A extends DateTime.Input>(input: A) => DateTime.PreserveZone<A> = Internal.makeUnsafe
Referenced by 1 symbols