(self: DateTime, that: DateTime): booleanProvides an Equivalence for comparing two DateTime values for equality.
Details
Two DateTime values are considered equivalent if they represent the same
point in time, regardless of their time zone.
Example (Comparing DateTime values for equivalence)
import { DateTime } from "effect"
const utc = DateTime.makeUnsafe("2024-01-01T12:00:00Z")
const zoned = DateTime.makeZonedUnsafe("2024-01-01T12:00:00Z", {
timeZone: "Europe/London"
})
console.log(DateTime.Equivalence(utc, zoned)) // trueexport const const Equivalence: Equ.Equivalence<DateTime>Provides an Equivalence for comparing two DateTime values for equality.
Details
Two DateTime values are considered equivalent if they represent the same
point in time, regardless of their time zone.
Example (Comparing DateTime values for equivalence)
import { DateTime } from "effect"
const utc = DateTime.makeUnsafe("2024-01-01T12:00:00Z")
const zoned = DateTime.makeZonedUnsafe("2024-01-01T12:00:00Z", {
timeZone: "Europe/London"
})
console.log(DateTime.Equivalence(utc, zoned)) // true
Equivalence: import EquEqu.type Equivalence<in A> = (
self: A,
that: A
) => boolean
Represents an equivalence relation over type A.
When to use
Use as a type annotation when you accept or return an equivalence function.
Details
- Returns
boolean: true if values are equivalent, false otherwise
- Must satisfy reflexive, symmetric, and transitive properties
Example (Defining simple number equivalence)
import type { Equivalence } from "effect"
const numberEq: Equivalence.Equivalence<number> = (a, b) => a === b
console.log(numberEq(1, 1)) // true
console.log(numberEq(1, 2)) // false
Example (Defining custom object equivalence)
import type { Equivalence } from "effect"
interface Point {
x: number
y: number
}
const pointEq: Equivalence.Equivalence<Point> = (a, b) =>
a.x === b.x && a.y === b.y
console.log(pointEq({ x: 1, y: 2 }, { x: 1, y: 2 })) // true
Equivalence<type DateTime = Utc | ZonedA DateTime represents a point in time. It can optionally have a time zone
associated with it.
Companion namespace containing the public helper types used by DateTime
constructors, parts APIs, formatting, and date/time arithmetic.
DateTime> = import InternalInternal.const Equivalence: Equ.Equivalence<DateTime.DateTime>Equivalence