effect-io-ai

Package: effect
Module: DateTime

DateTime.distance

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)
})

Signature

declare const distance: { (other: DateTime): (self: DateTime) => Duration.Duration; (self: DateTime, other: DateTime): Duration.Duration; }

Source

Since v3.6.0