bigbuffet-rw/app/soapbox/utils/ads.ts
2022-08-26 10:14:56 -05:00

16 lines
470 B
TypeScript

import type { Ad } from 'soapbox/features/ads/providers';
/** Time (ms) window to not display an ad if it's about to expire. */
const AD_EXPIRY_THRESHOLD = 5 * 60 * 1000;
/** Whether the ad is expired or about to expire. */
const isExpired = (ad: Ad, threshold = AD_EXPIRY_THRESHOLD): boolean => {
if (ad.expires) {
const now = new Date();
return now.getTime() > (ad.expires.getTime() - threshold);
} else {
return false;
}
};
export { isExpired };