All files day-of-week.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x                     1x 23x 23x 23x 23x 13x 13x   10x 10x  
import { type DateOptions, day, type DayOfWeek, daysPerWeek } from './date.ts';
import { modulo } from './modulo.ts';
 
/**
 * Determine the day of the week for a specific date
 * @param input - The date
 * @param options - see {@link DateOptions}
 * @defaultValue utc false
 * @returns The date value for midnight on the first day of the specified year
 * @group Time
 * @category Week
 */
export function dayOfWeek(
  input: Date,
  { utc = false, firstDayOfWeek = day.sunday }: DateOptions = {},
): DayOfWeek {
  if (utc) {
    return modulo(input.getUTCDay() + daysPerWeek - firstDayOfWeek, daysPerWeek) as DayOfWeek;
  }
 
  return modulo(input.getDay() + daysPerWeek - firstDayOfWeek, daysPerWeek) as DayOfWeek;
}