bigbuffet-rw/app/soapbox/utils/ads.ts

17 lines
491 B
TypeScript
Raw Normal View History

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