(self: DateTime, that: DateTime): OrderingProvides an Order for comparing and sorting DateTime values.
Details
DateTime values are ordered by their epoch milliseconds, so earlier times
come before later times regardless of time zone.
Example (Sorting DateTime values chronologically)
import { Array, DateTime } from "effect"
const dates = [
DateTime.makeUnsafe("2024-03-01"),
DateTime.makeUnsafe("2024-01-01"),
DateTime.makeUnsafe("2024-02-01")
]
const sorted = Array.sort(dates, DateTime.Order)
// Results in chronological order: 2024-01-01, 2024-02-01, 2024-03-01export const const Order: order.Order<DateTime>Provides an Order for comparing and sorting DateTime values.
Details
DateTime values are ordered by their epoch milliseconds, so earlier times
come before later times regardless of time zone.
Example (Sorting DateTime values chronologically)
import { Array, DateTime } from "effect"
const dates = [
DateTime.makeUnsafe("2024-03-01"),
DateTime.makeUnsafe("2024-01-01"),
DateTime.makeUnsafe("2024-02-01")
]
const sorted = Array.sort(dates, DateTime.Order)
// Results in chronological order: 2024-01-01, 2024-02-01, 2024-03-01
Order: import orderorder.interface Order<in A>Represents a total ordering for values of type A.
When to use
Use when you need to define how values of a type are compared.
Details
An order returns -1 when the first value is less than the second, 0 when
the values are equal according to this ordering, and 1 when the first value
is greater than the second. It must satisfy total ordering laws: totality,
antisymmetry, and transitivity.
Example (Defining a custom Order)
import { Order } from "effect"
const byAge: Order.Order<{ name: string; age: number }> = (self, that) => {
if (self.age < that.age) return -1
if (self.age > that.age) return 1
return 0
}
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 25 }
console.log(byAge(person1, person2)) // 1
Order<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 Order: order.Order<DateTime.DateTime>Order