{"record":{"id":"4e23dc4fb774faee","repo":"phacility/phabricator","slug":"weekday-s-is-not-a-valid-weekday-constant-vali","errorCode":null,"errorMessage":"Weekday \"%s\" is not a valid weekday constant. Valid constants are: %s.","messagePattern":"Weekday \"(.+?)\" is not a valid weekday constant\\. Valid constants are: (.+?)\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/calendar/parser/data/PhutilCalendarRecurrenceRule.php","lineNumber":331,"sourceCode":"  private static function getWeekdayIndexMap() {\n    static $map = array(\n      self::WEEKDAY_SUNDAY => self::WEEKINDEX_SUNDAY,\n      self::WEEKDAY_MONDAY => self::WEEKINDEX_MONDAY,\n      self::WEEKDAY_TUESDAY => self::WEEKINDEX_TUESDAY,\n      self::WEEKDAY_WEDNESDAY => self::WEEKINDEX_WEDNESDAY,\n      self::WEEKDAY_THURSDAY => self::WEEKINDEX_THURSDAY,\n      self::WEEKDAY_FRIDAY => self::WEEKINDEX_FRIDAY,\n      self::WEEKDAY_SATURDAY => self::WEEKINDEX_SATURDAY,\n    );\n\n    return $map;\n  }\n\n  private static function getWeekdayIndex($weekday) {\n    $map = self::getWeekdayIndexMap();\n    if (!isset($map[$weekday])) {\n      $constants = array_keys($map);\n      throw new Exception(\n        pht(\n          'Weekday \"%s\" is not a valid weekday constant. Valid constants '.\n          'are: %s.',\n          $weekday,\n          implode(', ', $constants)));\n    }\n\n    return $map[$weekday];\n  }\n\n  public function setStartDateTime(PhutilCalendarDateTime $start) {\n    $this->startDateTime = $start;\n    return $this;\n  }\n\n  public function getStartDateTime() {\n    return $this->startDateTime;\n  }","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/calendar/parser/data/PhutilCalendarRecurrenceRule.php#L313-L349","documentation":"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.","triggerScenarios":"Passing 'MONDAY', 'mon', 'M0', or '' wherever a WEEKDAY_* constant is expected; setWKST('XX'); constructing rules from data whose weekday tokens use full names.","commonSituations":"Full-name weekdays ('Monday') from user input or external systems; case sensitivity after lowercasing tokens; locale-specific weekday names.","solutions":["Use the two-letter uppercase constants SU, MO, TU, WE, TH, FR, SA.","Reference the class constants (PhutilCalendarRecurrenceRule::WEEKDAY_MONDAY etc.) instead of string literals.","Normalize external weekday names through an explicit map to the two-letter constants before building rules."],"exampleFix":"// before\n$rule->setWKST('SUNDAY');\n// after\n$rule->setWKST(PhutilCalendarRecurrenceRule::WEEKDAY_SUNDAY);","handlingStrategy":"type-guard","validationCode":"// Normalize any weekday token to the two-letter constants:\n$map = array(\n  'SU' => 'SU', 'SUN' => 'SU', 'SUNDAY' => 'SU',\n  'MO' => 'MO', 'MON' => 'MO', 'MONDAY' => 'MO',\n  'TU' => 'TU', 'TUE' => 'TU', 'TUESDAY' => 'TU',\n  'WE' => 'WE', 'WED' => 'WE', 'WEDNESDAY' => 'WE',\n  'TH' => 'TH', 'THU' => 'TH', 'THURSDAY' => 'TH',\n  'FR' => 'FR', 'FRI' => 'FR', 'FRIDAY' => 'FR',\n  'SA' => 'SA', 'SAT' => 'SA', 'SATURDAY' => 'SA',\n);\n$token = idx($map, strtoupper(trim($token)));\nif ($token === null) {\n  // reject before it reaches the RRULE API\n}","typeGuard":"function isWeekdayConstant($token) {\n  $constants = array('SU','MO','TU','WE','TH','FR','SA');\n  return in_array(strtoupper(trim((string)$token)), $constants, true);\n}","tryCatchPattern":null,"preventionTips":["Always pass the WEEKDAY_* class constants rather than hand-written strings.","Normalize full/abbreviated weekday names to two-letter constants at ingest.","Uppercase and trim tokens from external sources."],"tags":["phutil","calendar","rrule","weekday","invalid-value"],"backgroundTag":"invalid-weekday-value","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}