2023-05-02 16:30:21 -07:00
|
|
|
import type { Ad } from 'soapbox/schemas';
|
2022-08-26 08:14:56 -07:00
|
|
|
|
|
|
|
/** 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. */
|
2023-06-19 14:49:42 -07:00
|
|
|
const isExpired = (ad: Pick<Ad, 'expires_at'>, threshold = AD_EXPIRY_THRESHOLD): boolean => {
|
2022-10-20 14:29:14 -07:00
|
|
|
if (ad.expires_at) {
|
2022-08-26 08:14:56 -07:00
|
|
|
const now = new Date();
|
2022-10-20 14:29:14 -07:00
|
|
|
return now.getTime() > (new Date(ad.expires_at).getTime() - threshold);
|
2022-08-26 08:14:56 -07:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export { isExpired };
|