languagetool-org/languagetool · error
Could not find day of week for '<dayStr>'
Error message
Could not find day of week for '<dayStr>'
What it means
DateCheckFilter for Italian validates that a day-of-week found in text matches a recognized Italian weekday name or abbreviation. getDayOfWeek throws this RuntimeException when the extracted day string matches none of the known prefixes (lu, ma, me, gi, ve, sa) or full names. The filter assumes the regex that feeds it only matches valid weekdays, so an unmatched string indicates the rule regex and the filter are out of sync.
Source
Thrown at languagetool-language-modules/it/src/main/java/org/languagetool/rules/it/DateCheckFilter.java:48
public class DateCheckFilter extends AbstractDateCheckFilter {
@Override
protected Calendar getCalendar() {
return Calendar.getInstance(Locale.UK);
}
@SuppressWarnings("ControlFlowStatementWithoutBraces")
@Override
protected int getDayOfWeek(String dayStr) {
String day = dayStr.toLowerCase();
if (day.startsWith("do") || day.equals("domenica")) return Calendar.SUNDAY;
if (day.startsWith("lu") || day.equals("lunedì")) return Calendar.MONDAY;
if (day.startsWith("ma") || day.equals("martedì")) return Calendar.TUESDAY;
if (day.startsWith("me") || day.equals("mercoledì")) return Calendar.WEDNESDAY;
if (day.startsWith("gi") || day.equals("giovedì")) return Calendar.THURSDAY;
if (day.startsWith("ve") || day.equals("venerdì")) return Calendar.FRIDAY;
if (day.startsWith("sa") || day.equals("sabato")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
}
@SuppressWarnings("ControlFlowStatementWithoutBraces")
@Override
protected String getDayOfWeek(Calendar date) {
String englishDay = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.UK);
if (englishDay.equals("Sunday")) return "domenica";
if (englishDay.equals("Monday")) return "lunedì";
if (englishDay.equals("Tuesday")) return "martedì";
if (englishDay.equals("Wednesday")) return "mercoledì";
if (englishDay.equals("Thursday")) return "giovedì";
if (englishDay.equals("Friday")) return "venerdì";
if (englishDay.equals("Saturday")) return "sabato";
return "";
}
@SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
@OverrideView on GitHub (pinned to 2e990059ce)
Solutions
- Add the missing day mapping (notably Sunday: if (day.startsWith("do") || day.equals("domenica")) return Calendar.SUNDAY;) to getDayOfWeek
- Check the exception message for the exact day string and verify how the calling rule's regex captured it (case, accents, partial word)
- Ensure the rule regex only matches tokens covered by the mapping, or make matching case-insensitive/accent-aware before lookup
Example fix
// before
if (day.startsWith("sa") || day.equals("sabato")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
// after
if (day.startsWith("sa") || day.equals("sabato")) return Calendar.SATURDAY;
if (day.startsWith("do") || day.equals("domenica")) return Calendar.SUNDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'"); Defensive patterns
Strategy: validation
Validate before calling
Set<String> known = Set.of("lu","ma","me","gi","ve","sa","lunedì","martedì","mercoledì","giovedì","venerdì","sabato");
String d = dayStr.toLowerCase();
if (!known.stream().anyMatch(d::startsWith)) throw new IllegalArgumentException("Unrecognized Italian weekday: " + dayStr); Type guard
boolean isItalianWeekday(String s) { String d = s == null ? "" : s.toLowerCase(); return d.startsWith("lu")||d.startsWith("ma")||d.startsWith("me")||d.startsWith("gi")||d.startsWith("ve")||d.startsWith("sa"); } Try / catch
try { cal.set(Calendar.DAY_OF_WEEK, filter.getDayOfWeek(dayStr)); } catch (RuntimeException e) { log.warn("Unknown weekday token: {}", dayStr); /* skip rule match */ } Prevention
- Keep the rule regex alternation and getDayOfWeek branches in sync; add a unit test enumerating every weekday form the regex can emit
- Include Sunday ('dom'/'domenica') coverage tests — it is absent in the current chain
- Normalize case and accents before lookup
When it happens
Trigger: A grammar rule matches a token as a weekday and passes it to getDayOfWeek, but the token is not one of lunedì/lu, martedì/ma, mercoledì/me, giovedì/gi, venerdì/ve, sabato/sa (e.g. 'dom' or 'domenica', which has no mapping — Sunday is missing from the chain).
Common situations: Text contains 'domenica' (Sunday) matched by the date rule but the mapping has no Sunday branch; adding new Italian weekday spellings or abbreviations to the rule regex without updating getDayOfWeek; case/accents normalized differently than expected.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Could not find month '<monthStr>'
- Could not find day of week for '<dayStr>'
- Could not find month '<monthStr>'
- Could not find day of week for '<dayStr>'
- Could not find month '<monthStr>'
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/bc15666801e90d3b.
Report an issue: GitHub.