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
- Ensure the DatetimeParts passed in have dayOfWeek computed (derive it via new Date(...).getDay() before calling).
- Guard the caller: if dayOfWeek is missing, compute the full date parts first instead of calling getStartOfWeek.
- Use Ion's own date parsers to build parts so dayOfWeek is populated consistently.
- 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
- Always populate dayOfWeek when building DatetimeParts for week math.
- Derive dayOfWeek via Date.getDay() at the point you build parts.
- Unit-test week helpers with complete parts objects.
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
- No day provided
- Invalid hour cycle "${hourCycle}"
- Invalid hour cycle "${hourCycle}"
- Hour value not found from DateTimeFormat
- Invalid hour cycle "${hourCycle}"
AI-assisted analysis of ionic-team/ionic-framework@625f9c38ad (2026-08-12).
Data as JSON: /api/errors/c791785f87c94199.
Report an issue: GitHub.