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.getDayOfWeek() maps Russian weekday names and abbreviations (пн, вт, ср...) to java.util.Calendar constants. When the matched token in a date expression is not in its hardcoded prefix/equals list, it throws this RuntimeException. This means the filter saw a weekday token it does not recognize, typically due to an inflected or unusual form not covered by the rules.
Source
Thrown at languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/DateCheckFilter.java:46
public class DateCheckFilter extends AbstractDateCheckFilter {
@Override
protected Calendar getCalendar() {
return Calendar.getInstance(Locale.forLanguageTag("ru"));
}
@SuppressWarnings("ControlFlowStatementWithoutBraces")
@Override
protected int getDayOfWeek(String dayStr) {
String day = dayStr.toLowerCase();
if (day.startsWith("пн") || day.equals("понедельник")) return Calendar.MONDAY;
if (day.startsWith("вт")) return Calendar.TUESDAY;
if (day.startsWith("ср")) return Calendar.WEDNESDAY;
if (day.startsWith("чт") || day.equals("четверг")) return Calendar.THURSDAY;
if (day.equals("пт") || day.startsWith ("пятниц")) return Calendar.FRIDAY;
if (day.startsWith("сб") || day.startsWith ("суббот")) return Calendar.SATURDAY;
if (day.startsWith("вс") || day.equals("воскресенье")) return Calendar.SUNDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
}
@Override
protected String getDayOfWeek(Calendar date) {
return date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.forLanguageTag("ru"));
}
@SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
@Override
protected int getMonth(String monthStr) {
String mon = monthStr.toLowerCase();
if (mon.equals("январь") || monthStr.equals("I") || mon.equals("января") || mon.equals("янв")) return 1;
if (mon.equals("февраль") || monthStr.equals("II") || mon.equals("февраля") || mon.equals("фев")) return 2;
if (mon.equals("март") || monthStr.equals("III") || mon.equals("марта") || mon.equals("мар")) return 3;
if (mon.equals("апрель") || monthStr.equals("IV") || mon.equals("апреля") || mon.equals("апр")) return 4;
if (mon.equals("май") || monthStr.equals("V") || mon.equals("мая")) return 5;
if (mon.equals("июнь") || monthStr.equals("VI") || mon.equals("июня") || mon.equals("ин")) return 6;
if (mon.equals("июль") || monthStr.equals("VII") || mon.equals("июля") || mon.equals("ил")) return 7;View on GitHub (pinned to 2e990059ce)
Solutions
- Add the failing token's prefix/equals case to the if-chain in DateCheckFilter.getDayOfWeek (languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/DateCheckFilter.java:46) and return the matching Calendar constant
- Find the actual token from the exception message and check which regex rule produced it, then constrain the rule so only known weekday forms reach the filter
- Add a unit test in DateCheckFilterTest for the new token to prevent regressions
- As a defensive measure, replace the throw with a logged fallback (return -1) if you maintain a fork, so unmatched tokens do not crash rule evaluation
Example fix
// before
if (day.startsWith("вт")) return Calendar.TUESDAY;
...
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
// after
if (day.startsWith("вт") || day.startsWith("вторник")) return Calendar.TUESDAY;
...
if (day.startsWith("пн") || day.startsWith("понедель")) return Calendar.MONDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'"); Defensive patterns
Strategy: validation
Validate before calling
private static final Set<String> KNOWN_DAYS = Set.of("пн","вт","ср","чт","пт","сб","вс","понедель","вторник","сред","четверг","пятниц","суббот","воскресень");
boolean daySupported(String day) {
return KNOWN_DAYS.stream().anyMatch(day::startsWith);
}
// call daySupported(token) before invoking the date filter Type guard
boolean isRecognizedRussianWeekday(String token) {
String[] prefixes = {"пн","вт","ср","чт","пт","сб","вс","понедель","вторник","сред","четверг","пятниц","суббот","воскресень"};
for (String p : prefixes) if (token.startsWith(p)) return true;
return false;
} Try / catch
try {
result = filter.filter(readings, args);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Could not find day of week")) {
log.warn("Unrecognized weekday token skipped: {}", e.getMessage());
} else { throw e; }
} Prevention
- Keep the weekday prefix list in sync with every regex rule that can match day tokens
- Add unit tests covering all inflected forms your rules accept
- Diff DateCheckFilter and DateFilterHelper day lists when changing either
- Prefer startsWith over equals for full-form words to absorb inflections
When it happens
Trigger: A Russian date rule matched text whose weekday field is an unrecognized form, e.g. a rare inflection like 'во вторник' handled incorrectly, an abbreviation not covered ('втор'), a misspelling, or a form added by a new regex rule that was not synced with getDayOfWeek's prefix list. Any call to DateCheckFilter with a day-of-week token failing all startsWith/equals checks reaches the throw.
Common situations: Adding/extending Russian date regex rules in the ru module without updating DateCheckFilter; users writing dates with inflected weekday forms ('понедельник' vs covered prefix); corpus/grammar tests containing date variants the hard-coded list omits; typos in test sentences.
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 tag and disambiguate '<token>'
- Could not find day of week for '" + dayStr + "'
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/1c82dab27b35b94d.
Report an issue: GitHub.