Hyperlinkv0.8.0-beta.28

DateTime

DateTime.distanceconsteffect/DateTime.ts:1252
(other: DateTime): (self: DateTime) => Duration.Duration
(self: DateTime, other: DateTime): Duration.Duration

Computes the difference between two DateTime values, returning a Duration representing the amount of time between them.

Details

If other is after self, the result will be a positive Duration. If other is before self, the result will be a negative Duration. If they are equal, the result will be a Duration of zero.

Example (Measuring distance between DateTime values)

import { DateTime, Effect } from "effect"

Effect.gen(function*() {
  const now = yield* DateTime.now
  const other = DateTime.add(now, { minutes: 1 })

  // returns Duration.minutes(1)
  DateTime.distance(now, other)
})
comparisons
export const distance: {
  (other: DateTime): (self: DateTime) => Duration.Duration
  (self: DateTime, other: DateTime): Duration.Duration
} = Internal.distance