forked from DevExpress/DevExtreme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
56 lines (48 loc) · 1.76 KB
/
utils.js
File metadata and controls
56 lines (48 loc) · 1.76 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
import { dinnerTime, holidays } from './data.js';
export default class Utils {
static isHoliday(date) {
const localeDate = date.toLocaleDateString();
return holidays.filter((holiday) => holiday.toLocaleDateString() === localeDate).length > 0;
}
static isWeekend(date) {
const day = date.getDay();
return day === 0 || day === 6;
}
static isDisableDate(date) {
return Utils.isHoliday(date) || Utils.isWeekend(date);
}
static isDinner(date) {
const hours = date.getHours();
return hours >= dinnerTime.from && hours < dinnerTime.to;
}
static hasCoffeeCupIcon(date) {
const hours = date.getHours();
const minutes = date.getMinutes();
return hours === dinnerTime.from && minutes === 0;
}
static isValidAppointment(component, appointmentData) {
const startDate = appointmentData.startDate ? new Date(appointmentData.startDate) : new Date();
const endDate = appointmentData.endDate ? new Date(appointmentData.endDate) : new Date();
const cellDuration = Number(component.option('cellDuration'));
return Utils.isValidAppointmentInterval(startDate, endDate, cellDuration);
}
static isValidAppointmentInterval(startDate, endDate, cellDuration) {
const edgeEndDate = new Date(endDate.getTime() - 1);
if (!Utils.isValidAppointmentDate(edgeEndDate)) {
return false;
}
const durationInMs = cellDuration * 60 * 1000;
const date = startDate;
while (date <= endDate) {
if (!Utils.isValidAppointmentDate(date)) {
return false;
}
const newDateTime = date.getTime() + durationInMs - 1;
date.setTime(newDateTime);
}
return true;
}
static isValidAppointmentDate(date) {
return !Utils.isHoliday(date) && !Utils.isDinner(date) && !Utils.isWeekend(date);
}
}