tiempo

isFuture

Check if a datetime is in the future

Returns true if the given datetime is in the future (after the current instant).

Signature

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

Parameters

ParameterTypeDescription
dateTemporal.Instant | Temporal.ZonedDateTimeThe datetime to check

Returns

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

Examples

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

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

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

With Instant

const futureInstant = Temporal.Now.instant().add({ hours: 1 });
isFuture(futureInstant); // true

Works with any timezone

const futureInTokyo = Temporal.ZonedDateTime.from('2100-01-01T00:00:00+09:00[Asia/Tokyo]');
isFuture(futureInTokyo); // true

Common Patterns

Validate event dates

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

function validateEventStart(start: Temporal.ZonedDateTime) {
  if (!isFuture(start)) {
    throw new Error('Event start date must be in the future');
  }
}

On this page