ionic-team/ionic-framework · error · Error

No day of week provided

Error message

No day of week provided

What it means

Thrown by getStartOfWeek() in manipulation.ts when refParts.dayOfWeek is null or undefined. getStartOfWeek computes the Sunday (or firstDay) anchor of the week by subtracting dayOfWeek days, so a missing dayOfWeek makes the math impossible. This is a data-integrity guard, not user input validation.

Source

Thrown at core/src/components/datetime/utils/manipulation.ts:92

  /**
   * If PM and 12pm
   * just return 12:00
   * since it is already
   * in 24 hour format.
   * Otherwise add 12 hours
   * to the time.
   */
  if (hour === 12) {
    return 12;
  }

  return hour + 12;
};

export const getStartOfWeek = (refParts: DatetimeParts): DatetimeParts => {
  const { dayOfWeek } = refParts;
  if (dayOfWeek === null || dayOfWeek === undefined) {
    throw new Error('No day of week provided');
  }

  return subtractDays(refParts, dayOfWeek);
};

export const getEndOfWeek = (refParts: DatetimeParts): DatetimeParts => {
  const { dayOfWeek } = refParts;
  if (dayOfWeek === null || dayOfWeek === undefined) {
    throw new Error('No day of week provided');
  }

  return addDays(refParts, 6 - dayOfWeek);
};

export const getNextDay = (refParts: DatetimeParts): DatetimeParts => {
  return addDays(refParts, 1);
};

View on GitHub (pinned to 625f9c38ad)

Solutions

  1. Ensure the DatetimeParts passed in have dayOfWeek computed (derive it via new Date(...).getDay() before calling).
  2. Guard the caller: if dayOfWeek is missing, compute the full date parts first instead of calling getStartOfWeek.
  3. Use Ion's own date parsers to build parts so dayOfWeek is populated consistently.
  4. Add a unit test that asserts dayOfWeek is non-null for every parts object you feed week helpers.

Example fix

// before
const start = getStartOfWeek({ month: 5, day: 18, year: 2021 }); // dayOfWeek missing

// after
const d = new Date(2021, 4, 18);
const start = getStartOfWeek({ month: 5, day: 18, year: 2021, dayOfWeek: d.getDay() });
Defensive patterns

Strategy: validation

Validate before calling

function withDayOfWeek(parts: DatetimeParts): DatetimeParts {
  if (parts.dayOfWeek == null && parts.day != null && parts.year != null && parts.month != null) {
    return { ...parts, dayOfWeek: new Date(parts.year, parts.month - 1, parts.day).getDay() };
  }
  return parts;
}
const start = getStartOfWeek(withDayOfWeek(parts));

Type guard

function hasDayOfWeek(p: DatetimeParts): p is DatetimeParts & { dayOfWeek: number } {
  return p.dayOfWeek !== null && p.dayOfWeek !== undefined;
}

Prevention

When it happens

Trigger: getStartOfWeek is called with a DatetimeParts object whose dayOfWeek was never populated or was explicitly set to null - e.g. parts built from a year/month-only value, or a manually constructed object missing the field.

Common situations: Constructing DatetimeParts by hand from a partial date; date-only or month-year presentations where dayOfWeek is not computed; a parsing bug that drops dayOfWeek when reading an ISO string without a day.

Related errors


AI-assisted analysis of ionic-team/ionic-framework@625f9c38ad (2026-08-12). Data as JSON: /api/errors/c791785f87c94199. Report an issue: GitHub.