{"record":{"id":"dcba8d46fcda3952","repo":"PHPOffice/PhpSpreadsheet","slug":"invalid-operation-for-date-value-cf-rule-wizard","errorCode":null,"errorMessage":"Invalid Operation for Date Value CF Rule Wizard","messagePattern":"Invalid Operation for Date Value CF Rule Wizard","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/DateValue.php","lineNumber":102,"sourceCode":"        if ($conditional->getConditionType() !== Conditional::CONDITION_TIMEPERIOD) {\n            throw new Exception('Conditional is not a Date Value CF Rule conditional');\n        }\n\n        $wizard = new self($cellRange);\n        $wizard->style = $conditional->getStyle();\n        $wizard->stopIfTrue = $conditional->getStopIfTrue();\n        $wizard->operator = $conditional->getText();\n\n        return $wizard;\n    }\n\n    /**\n     * @param mixed[] $arguments\n     */\n    public function __call(string $methodName, array $arguments): self\n    {\n        if (!isset(self::MAGIC_OPERATIONS[$methodName])) {\n            throw new Exception('Invalid Operation for Date Value CF Rule Wizard');\n        }\n\n        $this->operator(self::MAGIC_OPERATIONS[$methodName]);\n\n        return $this;\n    }\n}\n","sourceCodeStart":84,"sourceCodeEnd":110,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/DateValue.php#L84-L110","documentation":"The DateValue (dates occurring) wizard works through __call with a fixed MAGIC_OPERATIONS map: yesterday, today, tomorrow, lastSevenDays (alias last7Days), lastWeek, thisWeek, nextWeek, lastMonth, thisMonth, nextMonth. Excel's timePeriod rule types define no year or quarter periods, so names like thisYear(), lastYear() or thisQuarter() throw Invalid Operation.","triggerScenarios":"->thisYear() or ->lastYear() (no year period exists in the wizard); ->thisQuarter(); misspellings such as ->tommorow() or ->last7days() (case matters: the alias is last7Days).","commonSituations":"UIs offering date filters like 'this year' or 'this quarter' that do not map 1:1 to Excel timePeriod types; translating UI labels mechanically into method names.","solutions":["Use only the supported period names: yesterday, today, tomorrow, lastSevenDays/last7Days, lastWeek, thisWeek, nextWeek, lastMonth, thisMonth, nextMonth","For year or quarter logic, build a Wizard\\Expression rule with a formula such as YEAR(A1)=YEAR(TODAY())","Validate dynamic period names against the supported list","Map UI filter labels explicitly to supported methods instead of mechanical conversion"],"exampleFix":"// before\n$wizard = (new Wizard('A1:E10'))->newRule(Wizard::DATES_OCCURRING);\n$wizard->thisYear();   // throws: no year period exists\n\n// after\n$wizard->thisMonth();  // or yesterday/today/tomorrow/lastSevenDays/lastWeek/thisWeek/nextWeek/lastMonth/nextMonth\n// for year logic use an expression rule instead:\n// (new Wizard('A1:E10'))->newRule(Wizard::EXPRESSION)->formula('YEAR(A1)=YEAR(TODAY())');","handlingStrategy":"validation","validationCode":"$allowed = ['yesterday', 'today', 'tomorrow', 'lastSevenDays', 'last7Days',\n    'lastWeek', 'thisWeek', 'nextWeek', 'lastMonth', 'thisMonth', 'nextMonth'];\n$period = $config['datePeriod'];\nif (!in_array($period, $allowed, true)) {\n    throw new InvalidArgumentException('Unsupported date period: ' . $period);\n}\n$wizard->$period();","typeGuard":null,"tryCatchPattern":"use PhpOffice\\PhpSpreadsheet\\Exception as PhpSpreadsheetException;\n\ntry {\n    $dateWizard->$period();\n} catch (PhpSpreadsheetException $e) {\n    // unsupported period such as thisYear/thisQuarter\n    throw new InvalidArgumentException('Unsupported date period: ' . $period, 0, $e);\n}","preventionTips":["Use only the eleven supported timePeriod method names","No year or quarter periods exist - build an Expression rule for those","Map UI date-filter labels to supported methods through an explicit whitelist","Method names are case-sensitive: last7Days works, last7days does not"],"tags":["php","phpspreadsheet","conditional-formatting","wizard","date-value","magic-methods"],"backgroundTag":"invalid-fluent-builder-method","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}