Raw
1 import { ModuleGiftCard } from "../types/loyalty";
2
3 /**
4 * Checks whether a gift card has expired.
5 *
6 * A gift card with a `null` expiration date never expires. Otherwise, the
7 * expiration date is compared against the current time. Both dates are
8 * compared as UTC timestamps.
9 *
10 * @param giftCard - The gift card to check.
11 * @returns Whether the gift card is expired.
12 *
13 * @example
14 * if (isGiftCardExpired(giftCard)) {
15 * // the gift card can no longer be redeemed
16 * }
17 */
18 export function isGiftCardExpired(
19 giftCard: Pick<ModuleGiftCard, "expires_at">
20 ): boolean {
21 if (!giftCard.expires_at) {
22 return false;
23 }
24
25 return new Date(giftCard.expires_at).getTime() <= Date.now();
26 }