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
): booleanParameters
| Parameter | Type | Description |
|---|---|---|
date | Temporal.Instant | Temporal.ZonedDateTime | The 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); // falseWith Instant
const futureInstant = Temporal.Now.instant().add({ hours: 1 });
isFuture(futureInstant); // trueWorks with any timezone
const futureInTokyo = Temporal.ZonedDateTime.from('2100-01-01T00:00:00+09:00[Asia/Tokyo]');
isFuture(futureInTokyo); // trueCommon 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');
}
}