{"record":{"id":"1c82dab27b35b94d","repo":"languagetool-org/languagetool","slug":"could-not-find-day-of-week-for-daystr-1c82da","errorCode":null,"errorMessage":"Could not find day of week for '<dayStr>'","messagePattern":"Could not find day of week for '<dayStr>'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/DateCheckFilter.java","lineNumber":46,"sourceCode":"public class DateCheckFilter extends AbstractDateCheckFilter {\n\n  @Override\n  protected Calendar getCalendar() {\n    return Calendar.getInstance(Locale.forLanguageTag(\"ru\"));\n  }\n\n  @SuppressWarnings(\"ControlFlowStatementWithoutBraces\")\n  @Override\n  protected int getDayOfWeek(String dayStr) {\n    String day = dayStr.toLowerCase();\n    if (day.startsWith(\"пн\") || day.equals(\"понедельник\")) return Calendar.MONDAY;\n    if (day.startsWith(\"вт\")) return Calendar.TUESDAY;\n    if (day.startsWith(\"ср\")) return Calendar.WEDNESDAY;\n    if (day.startsWith(\"чт\") || day.equals(\"четверг\")) return Calendar.THURSDAY;\n    if (day.equals(\"пт\") || day.startsWith (\"пятниц\")) return Calendar.FRIDAY;\n    if (day.startsWith(\"сб\") || day.startsWith (\"суббот\")) return Calendar.SATURDAY;\n    if (day.startsWith(\"вс\") || day.equals(\"воскресенье\")) return Calendar.SUNDAY;\n    throw new RuntimeException(\"Could not find day of week for '\" + dayStr + \"'\");\n  }\n\n  @Override\n  protected String getDayOfWeek(Calendar date) {\n    return date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.forLanguageTag(\"ru\"));\n  }\n\n  @SuppressWarnings({\"ControlFlowStatementWithoutBraces\", \"MagicNumber\"})\n  @Override\n  protected int getMonth(String monthStr) {\n    String mon = monthStr.toLowerCase();\n    if (mon.equals(\"январь\") || monthStr.equals(\"I\") || mon.equals(\"января\") || mon.equals(\"янв\")) return 1;\n    if (mon.equals(\"февраль\") || monthStr.equals(\"II\") ||  mon.equals(\"февраля\") || mon.equals(\"фев\")) return 2;\n    if (mon.equals(\"март\") || monthStr.equals(\"III\") || mon.equals(\"марта\") || mon.equals(\"мар\")) return 3;\n    if (mon.equals(\"апрель\") || monthStr.equals(\"IV\") || mon.equals(\"апреля\") || mon.equals(\"апр\")) return 4;\n    if (mon.equals(\"май\") || monthStr.equals(\"V\") || mon.equals(\"мая\")) return 5;\n    if (mon.equals(\"июнь\") || monthStr.equals(\"VI\") || mon.equals(\"июня\") || mon.equals(\"ин\")) return 6;\n    if (mon.equals(\"июль\") || monthStr.equals(\"VII\") || mon.equals(\"июля\") || mon.equals(\"ил\")) return 7;","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/DateCheckFilter.java#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nif (day.startsWith(\"вт\")) return Calendar.TUESDAY;\n...\nthrow new RuntimeException(\"Could not find day of week for '\" + dayStr + \"'\");\n// after\nif (day.startsWith(\"вт\") || day.startsWith(\"вторник\")) return Calendar.TUESDAY;\n...\nif (day.startsWith(\"пн\") || day.startsWith(\"понедель\")) return Calendar.MONDAY;\nthrow new RuntimeException(\"Could not find day of week for '\" + dayStr + \"'\");","handlingStrategy":"validation","validationCode":"private static final Set<String> KNOWN_DAYS = Set.of(\"пн\",\"вт\",\"ср\",\"чт\",\"пт\",\"сб\",\"вс\",\"понедель\",\"вторник\",\"сред\",\"четверг\",\"пятниц\",\"суббот\",\"воскресень\");\nboolean daySupported(String day) {\n  return KNOWN_DAYS.stream().anyMatch(day::startsWith);\n}\n// call daySupported(token) before invoking the date filter","typeGuard":"boolean isRecognizedRussianWeekday(String token) {\n  String[] prefixes = {\"пн\",\"вт\",\"ср\",\"чт\",\"пт\",\"сб\",\"вс\",\"понедель\",\"вторник\",\"сред\",\"четверг\",\"пятниц\",\"суббот\",\"воскресень\"};\n  for (String p : prefixes) if (token.startsWith(p)) return true;\n  return false;\n}","tryCatchPattern":"try {\n  result = filter.filter(readings, args);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Could not find day of week\")) {\n    log.warn(\"Unrecognized weekday token skipped: {}\", e.getMessage());\n  } else { throw e; }\n}","preventionTips":["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"],"tags":["java","russian","nlp","date-parsing","languagetool"],"backgroundTag":"invalid-enum-value","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}