phacility/phabricator · error · Exception

Weekday "%s" is not a valid weekday constant. Valid constant

Error message

Weekday "%s" is not a valid weekday constant. Valid constants are: %s.

What it means

PhutilCalendarRecurrenceRule::getWeekdayIndex() maps weekday constants (SU, MO, TU, WE, TH, FR, SA) to index numbers; passing anything else throws with the list of valid constants. It is reached internally when normalizing BYDAY values and WKST, so the error signals a weekday token that slipped past earlier validation or direct misuse of the API.

Source

Thrown at src/applications/calendar/parser/data/PhutilCalendarRecurrenceRule.php:331

  private static function getWeekdayIndexMap() {
    static $map = array(
      self::WEEKDAY_SUNDAY => self::WEEKINDEX_SUNDAY,
      self::WEEKDAY_MONDAY => self::WEEKINDEX_MONDAY,
      self::WEEKDAY_TUESDAY => self::WEEKINDEX_TUESDAY,
      self::WEEKDAY_WEDNESDAY => self::WEEKINDEX_WEDNESDAY,
      self::WEEKDAY_THURSDAY => self::WEEKINDEX_THURSDAY,
      self::WEEKDAY_FRIDAY => self::WEEKINDEX_FRIDAY,
      self::WEEKDAY_SATURDAY => self::WEEKINDEX_SATURDAY,
    );

    return $map;
  }

  private static function getWeekdayIndex($weekday) {
    $map = self::getWeekdayIndexMap();
    if (!isset($map[$weekday])) {
      $constants = array_keys($map);
      throw new Exception(
        pht(
          'Weekday "%s" is not a valid weekday constant. Valid constants '.
          'are: %s.',
          $weekday,
          implode(', ', $constants)));
    }

    return $map[$weekday];
  }

  public function setStartDateTime(PhutilCalendarDateTime $start) {
    $this->startDateTime = $start;
    return $this;
  }

  public function getStartDateTime() {
    return $this->startDateTime;
  }

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Use the two-letter uppercase constants SU, MO, TU, WE, TH, FR, SA.
  2. Reference the class constants (PhutilCalendarRecurrenceRule::WEEKDAY_MONDAY etc.) instead of string literals.
  3. Normalize external weekday names through an explicit map to the two-letter constants before building rules.

Example fix

// before
$rule->setWKST('SUNDAY');
// after
$rule->setWKST(PhutilCalendarRecurrenceRule::WEEKDAY_SUNDAY);
Defensive patterns

Strategy: type-guard

Validate before calling

// Normalize any weekday token to the two-letter constants:
$map = array(
  'SU' => 'SU', 'SUN' => 'SU', 'SUNDAY' => 'SU',
  'MO' => 'MO', 'MON' => 'MO', 'MONDAY' => 'MO',
  'TU' => 'TU', 'TUE' => 'TU', 'TUESDAY' => 'TU',
  'WE' => 'WE', 'WED' => 'WE', 'WEDNESDAY' => 'WE',
  'TH' => 'TH', 'THU' => 'TH', 'THURSDAY' => 'TH',
  'FR' => 'FR', 'FRI' => 'FR', 'FRIDAY' => 'FR',
  'SA' => 'SA', 'SAT' => 'SA', 'SATURDAY' => 'SA',
);
$token = idx($map, strtoupper(trim($token)));
if ($token === null) {
  // reject before it reaches the RRULE API
}

Type guard

function isWeekdayConstant($token) {
  $constants = array('SU','MO','TU','WE','TH','FR','SA');
  return in_array(strtoupper(trim((string)$token)), $constants, true);
}

Prevention

When it happens

Trigger: Passing 'MONDAY', 'mon', 'M0', or '' wherever a WEEKDAY_* constant is expected; setWKST('XX'); constructing rules from data whose weekday tokens use full names.

Common situations: Full-name weekdays ('Monday') from user input or external systems; case sensitivity after lowercasing tokens; locale-specific weekday names.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/4e23dc4fb774faee. Report an issue: GitHub.