<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
Dateinstance (invalid dates will throw anIllegalArgumentError) - The
numberof milliseconds since the Unix epoch - An object with the parts of a date
- A
stringthat can be parsed byDate.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"export const const makeUnsafe: <
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"
makeUnsafe: <function (type parameter) A in <A extends DateTime.Input>(input: A): DateTime.PreserveZone<A>A extends DateTime.type DateTime.Input = string | number | DateTime | Partial<DateTime.Parts> | DateTime.Instant | DateTime.InstantWithZone | DateInput accepted by DateTime.make, DateTime.makeUnsafe, and the zoned
constructors.
Details
Includes existing DateTime values, partial date parts, epoch-millisecond
objects, epoch milliseconds, JavaScript Date instances, and parseable date
strings.
Input>(input: A extends DateTime.Inputinput: function (type parameter) A in <A extends DateTime.Input>(input: A): DateTime.PreserveZone<A>A) => DateTime.type DateTime.PreserveZone<A extends DateTime.Input> = A extends Zoned ? Zoned : UtcType-level helper used by constructors to preserve a zoned input.
Details
When the input type is DateTime.Zoned, the result type is
DateTime.Zoned; otherwise the result type is DateTime.Utc.
PreserveZone<function (type parameter) A in <A extends DateTime.Input>(input: A): DateTime.PreserveZone<A>A> = import InternalInternal.const makeUnsafe: <
A extends DateTime.Input
>(
input: A
) => DateTime.PreserveZone<A>
makeUnsafe