| 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 |
1×
1×
1×
1×
1×
1×
77×
1×
1×
11×
11×
11×
11×
11×
11×
42×
11×
314×
44×
44×
314×
314×
11×
29×
11×
1×
56×
56×
56×
1×
56×
56×
56×
1×
536×
1×
2×
2×
1×
20×
20×
1×
20×
20×
1×
10×
10×
1×
10×
10×
1×
51×
1×
28×
| import { isNone, isPresent } from '@ember/utils';
export const weekdays = {
Sunday: 'Sunday',
Monday: 'Monday',
Tuesday: 'Tuesday',
Wednesday: 'Wednesday',
Thursday: 'Thursday',
Friday: 'Friday',
Saturday: 'Saturday'
}
export const weekdaysArray = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
]
export const monthsArray = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
export function getYearForRange({ start, end }) {
if (isPresent(start)) {
return start.getFullYear();
}
if (isPresent(end)) {
return end.getFullYear();
}
return (new Date()).getFullYear();
}
export function getMonthForRange({ start, end }) {
if (isPresent(start)) {
return start.getMonth();
}
if (isPresent(end)) {
return end.getMonth();
}
return (new Date()).getMonth();
}
export function abbreviationForWeekday(weekday) {
return weekdays[weekday].substring(0, 2);
}
const WEEK_LENGTH = 7;
export function getWeeksForMonth(month, year) {
const firstOfMonth = new Date(year, month, 1);
const firstDayOfWeek = firstOfMonth.getDay();
const weeks = [[]];
let currentWeek = weeks[0];
let currentDate = firstOfMonth;
for (let i = 0; i < firstDayOfWeek; i++) {
currentWeek.push(null);
}
while (currentDate.getMonth() === month) {
if (currentWeek.length === WEEK_LENGTH) {
currentWeek = [];
weeks.push(currentWeek);
}
currentWeek.push(currentDate);
currentDate = new Date(year, month, currentDate.getDate() + 1);
}
while (currentWeek.length < WEEK_LENGTH) {
currentWeek.push(null);
}
return weeks;
}
export function dateIsInRange(day, range) {
Iif (isNone(day)) {
return false;
}
const { start, end } = range;
return (isPresent(start) && day > start) && (isPresent(end) && day < end);
}
export function dateIsSelected(day, range) {
Iif (isNone(day)) {
return false;
}
const {start, end} = range;
return (isPresent(start) && isSameDay(start, day)) || (isPresent(end) && isSameDay(end, day));
}
export function isSameDay(day1, day2) {
return (
day1.getDate() === day2.getDate() &&
day1.getMonth() === day2.getMonth() &&
day1.getFullYear() === day2.getFullYear()
);
}
export function getNewRange(range, selected) {
Eif (isNone(range)) {
return { start: selected, end: selected };
}
let { start, end } = range;
if (isPresent(end) && start !== end) {
return { start: selected, end: selected };
}
if (isPresent(start)) {
if (selected < start) {
return { start: selected, end: selected };
}
return { start, end: selected };
}
if (isPresent(end)) {
if (selected < end) {
return { start: selected, end };
}
return { start: (start || end), end: selected };
}
return { start: selected, end: selected };
}
export function getNextDisplayMonth(month) {
Iif (month === 11) {
return 0;
}
return month + 1;
}
export function getNextDisplayYear(month, year) {
Iif (month === 11) {
return year + 1;
}
return year;
}
export function getPreviousDisplayMonth(month) {
Iif (month === 0) {
return 11;
}
return month - 1;
}
export function getPreviousDisplayYear(month, year) {
Iif (month === 0) {
return year - 1;
}
return year;
}
export function isDateAfter(date, dateToCompare) {
return date.getTime() > dateToCompare.getTime();
}
export function isDateBefore(date, dateToCompare) {
return date.getTime() < dateToCompare.getTime();
}
|