<A extends DateTime.Input>(input: A): Option.Option<
DateTime.PreserveZone<A>
>Creates a DateTime safely from supported input values.
Details
- A
DateTime - A JavaScript
Date - The number of milliseconds since the Unix epoch
- An object with date and time parts
- A string that can be parsed as a date
Returns Some with the constructed DateTime when the input is valid, or
None when construction would fail, including invalid Date instances or
unparseable strings.
Example (Creating optional DateTime values)
import { DateTime } from "effect"
// from Date
const fromDate = DateTime.make(new Date("2024-01-01T12:00:00Z"))
console.log(fromDate._tag) // "Some"
// from parts
const fromParts = DateTime.make({ year: 2024 })
console.log(fromParts._tag) // "Some"
// from string
const fromString = DateTime.make("2024-01-01")
console.log(fromString._tag) // "Some"
const invalid = DateTime.make("not a date")
console.log(invalid._tag) // "None"export const const make: <A extends DateTime.Input>(
input: A
) => Option.Option<DateTime.PreserveZone<A>>
Creates a DateTime safely from supported input values.
Details
- A
DateTime
- A JavaScript
Date
- The number of milliseconds since the Unix epoch
- An object with date and time parts
- A string that can be parsed as a date
Returns Some with the constructed DateTime when the input is valid, or
None when construction would fail, including invalid Date instances or
unparseable strings.
Example (Creating optional DateTime values)
import { DateTime } from "effect"
// from Date
const fromDate = DateTime.make(new Date("2024-01-01T12:00:00Z"))
console.log(fromDate._tag) // "Some"
// from parts
const fromParts = DateTime.make({ year: 2024 })
console.log(fromParts._tag) // "Some"
// from string
const fromString = DateTime.make("2024-01-01")
console.log(fromString._tag) // "Some"
const invalid = DateTime.make("not a date")
console.log(invalid._tag) // "None"
make: <function (type parameter) A in <A extends DateTime.Input>(input: A): Option.Option<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): Option.Option<DateTime.PreserveZone<A>>A) => import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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): Option.Option<DateTime.PreserveZone<A>>A>> = import InternalInternal.const make: <
A extends DateTime.DateTime.Input
>(
input: A
) => Option.Option<
DateTime.DateTime.PreserveZone<A>
>
make