{"record":{"id":"213cb3f0bd7dbf91","repo":"PHPOffice/PhpSpreadsheet","slug":"conditional-is-not-a-date-value-cf-rule-conditiona","errorCode":null,"errorMessage":"Conditional is not a Date Value CF Rule conditional","messagePattern":"Conditional is not a Date Value CF Rule conditional","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/DateValue.php","lineNumber":85,"sourceCode":"\n    public function getConditional(): Conditional\n    {\n        $this->setExpression();\n\n        $conditional = new Conditional();\n        $conditional->setConditionType(Conditional::CONDITION_TIMEPERIOD);\n        $conditional->setText($this->operator);\n        $conditional->setConditions([$this->expression]);\n        $conditional->setStyle($this->getStyle());\n        $conditional->setStopIfTrue($this->getStopIfTrue());\n\n        return $conditional;\n    }\n\n    public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface\n    {\n        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        }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/DateValue.php#L67-L103","documentation":"Wizard\\DateValue::fromConditional() rebuilds a dates-occurring wizard from an existing Conditional, and only CONDITION_TIMEPERIOD conditionals qualify (yesterday/today/this week/last month style rules). Cell value, text, expression and blanks rules use other condition types and are rejected up front rather than being misinterpreted as date rules.","triggerScenarios":"Calling DateValue::fromConditional() on a Conditional built by a CellValue, TextValue, Expression or Blanks wizard; passing a date comparison written as an expression formula instead of a true timePeriod rule.","commonSituations":"Rule editors that assume any date-related condition is a timePeriod rule; date logic stored as expression rules (e.g. A1>TODAY()) in imported files; generic conversion loops that force every rule through one factory.","solutions":["Check $conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD first","Use Wizard::fromConditional() to dispatch to the correct wizard automatically","For date formulas saved as expressions, use Wizard\\Expression::fromConditional() instead","Guard batch loops with try/catch"],"exampleFix":"// before\n$wizard = Wizard\\DateValue::fromConditional($conditional); // throws unless type is timePeriod\n\n// after\nuse PhpOffice\\PhpSpreadsheet\\Style\\Conditional;\n\nif ($conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD) {\n    $wizard = Wizard\\DateValue::fromConditional($conditional);\n} else {\n    $wizard = Wizard::fromConditional($conditional);\n}","handlingStrategy":"type-guard","validationCode":"use PhpOffice\\PhpSpreadsheet\\Style\\Conditional;\n\nif ($conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD) {\n    $wizard = Wizard\\DateValue::fromConditional($conditional, $cellRange);\n} else {\n    $wizard = Wizard::fromConditional($conditional, $cellRange);\n}","typeGuard":"function isDateValueConditional(Conditional $conditional): bool\n{\n    return $conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD;\n}","tryCatchPattern":"use PhpOffice\\PhpSpreadsheet\\Exception as PhpSpreadsheetException;\n\ntry {\n    $wizard = Wizard\\DateValue::fromConditional($conditional, $cellRange);\n} catch (PhpSpreadsheetException $e) {\n    $wizard = Wizard::fromConditional($conditional, $cellRange);\n}","preventionTips":["Check for CONDITION_TIMEPERIOD before using the DateValue factory","Treat date formulas saved as expressions as EXPRESSION rules","Use the generic Wizard::fromConditional() for imported or unknown rules","Remember date rules carry their period in getText(), not in conditions"],"tags":["php","phpspreadsheet","conditional-formatting","wizard","date-value","time-period","type-mismatch"],"backgroundTag":"conditional-rule-type-mismatch","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}