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

Portuguese DateFilterHelper.getDayOfWeek maps Portuguese weekday tokens (seg, ter, qua, qui, sex, sáb prefixes) to Calendar constants and throws this RuntimeException when none match. There is no Sunday ('dom'/'domingo') branch, so any Sunday token reaching the method throws.

Source

Thrown at languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/DateFilterHelper.java:45

 * @since 4.3
 */
class DateFilterHelper {

  protected Calendar getCalendar() {
    return Calendar.getInstance(Locale.UK);
  }

  @SuppressWarnings("ControlFlowStatementWithoutBraces")
  protected int getDayOfWeek(String dayStr) {
    String day = StringTools.trimSpecialCharacters(dayStr).toLowerCase();  // quickfix for special characters like soft hyphens
    if (day.startsWith("dom")) return Calendar.SUNDAY;
    if (day.startsWith("seg")) return Calendar.MONDAY;
    if (day.startsWith("ter")) return Calendar.TUESDAY;
    if (day.startsWith("qua")) return Calendar.WEDNESDAY;
    if (day.startsWith("qui")) return Calendar.THURSDAY;
    if (day.startsWith("sex")) return Calendar.FRIDAY;
    if (day.startsWith("sáb")) return Calendar.SATURDAY;
    throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
  }

  @SuppressWarnings("ControlFlowStatementWithoutBraces")
  protected String getDayOfWeek(Calendar date) {
    String englishDay = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.UK);
    if (englishDay.equals("Sunday")) return "domingo";
    if (englishDay.equals("Monday")) return "segunda-feira";
    if (englishDay.equals("Tuesday")) return "terça-feira";
    if (englishDay.equals("Wednesday")) return "quarta-feira";
    if (englishDay.equals("Thursday")) return "quinta-feira";
    if (englishDay.equals("Friday")) return "sexta-feira";
    if (englishDay.equals("Saturday")) return "sábado";
    return "";
  }

  @SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
  protected int getMonth(String monthStr) {
    String mon = StringTools.trimSpecialCharacters(monthStr).toLowerCase();  // quickfix for special characters like soft hyphens

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Add Sunday mapping: if (day.startsWith("dom")) return Calendar.SUNDAY;
  2. Handle both accented and unaccented 'sab'/'sáb': if (day.startsWith("sáb") || day.startsWith("sab")) return Calendar.SATURDAY;
  3. Check the message's day string and align the rule regex with the supported prefixes

Example fix

// before
if (day.startsWith("sáb")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
// after
if (day.startsWith("sáb") || day.startsWith("sab")) return Calendar.SATURDAY;
if (day.startsWith("dom")) return Calendar.SUNDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
Defensive patterns

Strategy: validation

Validate before calling

if (dayStr == null || !dayStr.toLowerCase().matches("(seg|ter|qua|qui|sex|sáb|sab|dom).*")) throw new IllegalArgumentException("Unrecognized Portuguese weekday: " + dayStr);

Type guard

boolean isPortugueseWeekday(String s) { String d = s == null ? "" : s.toLowerCase(); return d.startsWith("seg")||d.startsWith("ter")||d.startsWith("qua")||d.startsWith("qui")||d.startsWith("sex")||d.startsWith("sáb")||d.startsWith("sab")||d.startsWith("dom"); }

Try / catch

try { day = helper.getDayOfWeek(dayStr); } catch (RuntimeException e) { log.debug("Portuguese weekday unmatched: {}", dayStr); }

Prevention

When it happens

Trigger: A Portuguese date rule matches 'domingo'/'dom' (or any unrecognized weekday token) and calls getDayOfWeek; also 'sab' without the accent fails because the check is startsWith("sáb").

Common situations: Sunday-containing dates; unaccented input ('sabado', 'sab') from ASCII-normalized text; new abbreviations added to a rule regex without updating the helper.

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/f8113d4008ca2fb7. Report an issue: GitHub.