All files end-of-week.ts

100% Statements 22/22
100% Branches 2/2
100% Functions 1/1
100% Lines 22/22

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 23 24 25 26 27 28 29 30 31 32 33 341x 1x                     1x 16x 16x 16x 16x 8x 8x 8x 8x 8x 8x 8x 8x 8x   8x 8x 8x 8x 8x 8x  
import { type DateOptions, day, daysPerWeek } from './date.ts';
import { modulo } from './modulo.ts';
 
/**
 * Determine the last day of the week containing a date
 * @param input - The date
 * @param options - see {@link DateOptions}
 * @defaultValue utc false
 * @returns Midnight of the last day of the week containing the input date
 * @group Time
 * @category Week
 */
export function endOfWeek(
  input: Date,
  { utc = false, firstDayOfWeek = day.sunday }: DateOptions = {},
): Date {
  if (utc) {
    return new Date(
      Date.UTC(
        input.getUTCFullYear(),
        input.getUTCMonth(),
        input.getUTCDate() +
          modulo(daysPerWeek - input.getUTCDay() + firstDayOfWeek - 1, daysPerWeek),
      ),
    );
  }
 
  return new Date(
    input.getFullYear(),
    input.getMonth(),
    input.getDate() + modulo(daysPerWeek - input.getDay() + firstDayOfWeek - 1, daysPerWeek),
  );
}