mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-23 16:14:28 +01:00
Free gifting on thanksgiving
This commit is contained in:
committed by
Paul Miller
parent
8a427c62e8
commit
d7ee953fa7
@@ -5,3 +5,27 @@ export function subscriptionValid(subscriptionExpiresTimestamp?: number) {
|
||||
|
||||
return subscriptionExpiresTimestamp + GRACE > Math.ceil(Date.now() / 1000);
|
||||
}
|
||||
|
||||
export function isFreeGiftingDay() {
|
||||
const today = new Date();
|
||||
// days are 1 indexed, months are 0 indexed
|
||||
const isChristmas = today.getDate() === 25 && today.getMonth() === 11;
|
||||
|
||||
return isChristmas || isThanksgiving(today);
|
||||
}
|
||||
|
||||
function isThanksgiving(today: Date) {
|
||||
if (today.getMonth() !== 10) return false;
|
||||
|
||||
const year = today.getFullYear();
|
||||
const thanksgivingDay = new Date(year, 10, 1);
|
||||
|
||||
// Find out what day of the week Nov 1 is
|
||||
const dayOfWeek = thanksgivingDay.getDay();
|
||||
|
||||
// Calculate the date of the fourth Thursday in November
|
||||
thanksgivingDay.setDate(1 + ((4 - dayOfWeek) % 7) + 3 * 7);
|
||||
|
||||
// Compare the current date with Thanksgiving date
|
||||
return today.getDate() === thanksgivingDay.getDate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user