tiempo

isPast

Check if a datetime is in the past

Returns true if the given datetime is in the past (before the current instant).

Signature

function isPast(
  date: Temporal.Instant | Temporal.ZonedDateTime
): boolean

Parameters

ParameterTypeDescription
dateTemporal.Instant | Temporal.ZonedDateTimeThe datetime to check

Returns

true if the datetime is in the past, false otherwise.

Examples

import { isPast } from '@gobrand/tiempo';

const yesterday = Temporal.Now.zonedDateTimeISO().subtract({ days: 1 });
const tomorrow = Temporal.Now.zonedDateTimeISO().add({ days: 1 });

isPast(yesterday); // true
isPast(tomorrow);  // false

With Instant

const pastInstant = Temporal.Now.instant().subtract({ hours: 1 });
isPast(pastInstant); // true

On this page