@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
30 lines (28 loc) • 1.03 kB
JavaScript
import { Temporal } from "../../internal/temporal.js";
import { isValidUtc } from "../validate/isValidUtc.js";
// src/utc/compare/isAfterUtc.ts
/**
* Return whether `value1` represents an instant strictly after `value2`.
*
* - Uses Temporal.Instant.compare for comparison.
* - Returns false if either input is invalid.
*
* @param value1 first UTC datetime string
* @param value2 second UTC datetime string
* @returns `true` if `value1` is after `value2`, otherwise `false`
*
* @example isAfterUtc("2024-03-17T15:30:45Z", "2024-03-17T14:30:45Z") // true
* @example isAfterUtc("2024-03-17T14:30:45Z", "2024-03-17T14:30:45Z") // false
* @example isAfterUtc("2024-03-17T14:30:45Z", "invalid") // false
*/
function isAfterUtc(value1, value2) {
if (!isValidUtc(value1) || !isValidUtc(value2)) return false;
try {
const instant1 = Temporal.Instant.from(value1);
const instant2 = Temporal.Instant.from(value2);
return Temporal.Instant.compare(instant1, instant2) === 1;
} catch {
return false;
}
}
export { isAfterUtc };