File size: 685 Bytes
22df730
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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);
  }
}