languagetool-org/languagetool · error · RuntimeException

Could not find day of week for '<dayStr>'

Error message

Could not find day of week for '<dayStr>'

What it means

DateFilterHelper.getDayOfWeek() maps Russian weekday tokens (пн, вт, ср, чт, пт, сб, вс and their full forms via startsWith) to Calendar constants. Unmatched tokens trigger this RuntimeException. It is the sibling of DateCheckFilter's version but with a narrower prefix list, so forms matched by rules but absent here crash.

Source

Thrown at languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/DateFilterHelper.java:51

    return Calendar.getInstance(Locale.forLanguageTag("ru"));
  }

  @SuppressWarnings("ControlFlowStatementWithoutBraces")
  protected int getDayOfWeek(String dayStr) {
    String day = StringTools.trimSpecialCharacters(dayStr).toLowerCase();  // quickfix for special characters like soft hyphens
    if (day.startsWith("суб")) return Calendar.SATURDAY;
    if (day.startsWith("вс")) return Calendar.SUNDAY;
    if (day.startsWith("вос")) return Calendar.SUNDAY;
    if (day.startsWith("пн")) return Calendar.MONDAY;
    if (day.startsWith("пон")) return Calendar.MONDAY;
    if (day.startsWith("вт")) return Calendar.TUESDAY;
    if (day.startsWith("ср")) return Calendar.WEDNESDAY;
    if (day.startsWith("чт")) return Calendar.THURSDAY;
    if (day.startsWith("чет")) return Calendar.THURSDAY;
    if (day.startsWith("пт")) return Calendar.FRIDAY;
    if (day.startsWith("пят")) return Calendar.FRIDAY;
    if (day.startsWith("сб")) return Calendar.SATURDAY;
    throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
  }

  protected String getDayOfWeek(Calendar date) {
    return date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.forLanguageTag("ru"));
  }

  @SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
  protected int getMonth(String monthStr) {
    String mon = StringTools.trimSpecialCharacters(monthStr).toLowerCase();
    if (mon.startsWith("янв")) return 1;
    if (mon.startsWith("фев")) return 2;
    if (mon.startsWith("мар")) return 3;
    if (mon.startsWith("апр")) return 4;
    if (mon.startsWith("май")) return 5;
    if (mon.startsWith("мая")) return 5; //
    if (mon.startsWith("июн")) return 6;
    if (mon.startsWith("июл")) return 7;
    if (mon.startsWith("авг")) return 8;

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Add the failing token's prefix to DateFilterHelper.getDayOfWeek (DateFilterHelper.java:51) and return the correct Calendar constant
  2. Align this list with DateCheckFilter.getDayOfWeek so both cover the same forms (e.g. add 'пн'/понедельник and full-form branches present in the other class)
  3. Restrict the matching regex rule to known weekday forms
  4. Add a DateFilterHelperTest case for the token from the message

Example fix

// before
if (day.startsWith("сб")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
// after
if (day.startsWith("сб") || day.startsWith("суббот")) return Calendar.SATURDAY;
if (day.startsWith("вс") || day.startsWith("воскресень")) return Calendar.SUNDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> ok = Set.of("пн","вт","ср","чт","чет","пт","пят","сб","суб","вс","воскрес");
boolean supported(String day) {
  String d = day.toLowerCase(Locale.ROOT);
  return ok.stream().anyMatch(d::startsWith);
}
// gate the filter call on supported(token)

Type guard

boolean isKnownWeekdayAbbrev(String token) {
  String d = token.toLowerCase(Locale.ROOT);
  return d.matches("(пн|вт|ср|чт|чет|пт|пят|сб|суб|вс|воскрес|понедель|вторник|сред|четверг|пятниц|суббот).*");
}

Try / catch

try {
  analyzed = helper.filter(tokens, arguments);
} catch (RuntimeException e) {
  if (String.valueOf(e.getMessage()).contains("Could not find day of week")) {
    return Collections.emptyList(); // degrade gracefully for this match
  }
  throw e;
}

Prevention

When it happens

Trigger: A date rule matched a weekday form whose prefix is not in the list — notably 'понедельник/пн' and full forms like 'четверг' are only partially covered ('чет' covers четверг but e.g. an inflected 'четвергом' would match; a form like 'втр' or 'сред' handled differently could fail). Any token failing all startsWith checks in DateFilterHelper.getDayOfWeek (DateFilterHelper.java:51) throws.

Common situations: Relative-date rules in the ru module fed by tokens the helper list does not anticipate; divergent maintenance between DateCheckFilter and DateFilterHelper day lists; new abbreviations added to regexes but not to this helper; user text with misspelled weekdays.

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


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/a21e239841c20320. Report an issue: GitHub.