-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy paththemeDates.js
More file actions
114 lines (103 loc) · 2.55 KB
/
themeDates.js
File metadata and controls
114 lines (103 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as themeIds from "./themeIds";
function isInDateRange(date, dateLowerBound, dateUpperBound) {
if (date.getMonth() !== dateLowerBound.getMonth()) {
return false;
}
const currentDay = date.getDate();
return (
currentDay >= dateLowerBound.getDate() &&
currentDay <= dateUpperBound.getDate()
);
} //I think this is good enough for now. obviously doesn't work with dates that cross months.
let randomTheme;
export default function GetAutoThemeId() {
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
if (
isInDateRange(
currentDate,
new Date(`02/07/${currentYear}`),
new Date(`02/21/${currentYear}`)
)
) {
return themeIds.valentinesDayId;
}
if (
isInDateRange(
currentDate,
new Date(`03/04/${currentYear}`),
new Date(`03/21/${currentYear}`)
)
) {
return themeIds.feastOfSaintPatrickId;
}
if (
isInDateRange(
currentDate,
new Date(`09/22/${currentYear}`),
new Date(`09/30/${currentYear}`)
)
) {
return themeIds.autumnBId;
}
if (
isInDateRange(
currentDate,
new Date(`10/01/${currentYear}`),
new Date(`10/31/${currentYear}`)
) ||
isInDateRange(
currentDate,
new Date(`11/01/${currentYear}`),
new Date(`11/01/${currentYear}`)
)
) {
return themeIds.halloweenId;
}
if (
isInDateRange(
currentDate,
new Date(`06/01/${currentYear}`),
new Date(`06/30/${currentYear}`)
)
) {
return Math.floor(Math.random() * 2)
? themeIds.prideClassicId
: themeIds.prideVibrantId;
}
if (
isInDateRange(
currentDate,
new Date(`12/01/${currentYear}`),
new Date(`12/31/${currentYear}`)
)
) {
return Math.floor(Math.random() * 2)
? themeIds.christmasPeppermintHolidayId
: themeIds.christmasId;
}
if (randomTheme) {
return randomTheme;
}
const excludedThemes = new Set([
themeIds.aSuperSpecialAutoThemeSettingsId,
themeIds.christmasId,
themeIds.christmasPeppermintHolidayId,
themeIds.christmasWithoutSnowId,
themeIds.valentinesDayId,
themeIds.flamingoId,
themeIds.funId,
themeIds.prideClassicId,
themeIds.prideVibrantId,
themeIds.lightThemeId,
themeIds.feastOfSaintPatrickId,
themeIds.halloweenId,
themeIds.autumnBId
]);
const themeKeys = Object.keys(themeIds).filter(
(key) => !excludedThemes.has(themeIds[key])
);
randomTheme =
themeIds[themeKeys[Math.floor(Math.random() * themeKeys.length)]];
return randomTheme;
}