17 lines
470 B
TypeScript
17 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 };
|