File size: 778 Bytes
d76f93d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
export class DateUtils {
    private static readonly DAY_NAMES = [
        "sunday",
        "monday",
        "tuesday",
        "wednesday",
        "thursday",
        "friday",
        "saturday",
    ] as const;
    
    private static readonly DAY_MAP = Object.fromEntries(
        DateUtils.DAY_NAMES.map((day, index) => [index, day])
    );

    public static getDayName(date: Date | string): string {
        const dateObj = typeof date === "string" ? new Date(date) : date;
        const dayOfWeek = dateObj.getDay();
        return this.DAY_MAP[dayOfWeek];
    }

    public static isWorkingDay(
        date: Date | string,
        workDays: string[]
    ): boolean {
        const dayName = this.getDayName(date);
        return workDays.includes(dayName);
    }
}