PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Conditional is not a Date Value CF Rule conditional
Error message
Conditional is not a Date Value CF Rule conditional
What it means
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.
Source
Thrown at src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/DateValue.php:85
public function getConditional(): Conditional
{
$this->setExpression();
$conditional = new Conditional();
$conditional->setConditionType(Conditional::CONDITION_TIMEPERIOD);
$conditional->setText($this->operator);
$conditional->setConditions([$this->expression]);
$conditional->setStyle($this->getStyle());
$conditional->setStopIfTrue($this->getStopIfTrue());
return $conditional;
}
public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface
{
if ($conditional->getConditionType() !== Conditional::CONDITION_TIMEPERIOD) {
throw new Exception('Conditional is not a Date Value CF Rule conditional');
}
$wizard = new self($cellRange);
$wizard->style = $conditional->getStyle();
$wizard->stopIfTrue = $conditional->getStopIfTrue();
$wizard->operator = $conditional->getText();
return $wizard;
}
/**
* @param mixed[] $arguments
*/
public function __call(string $methodName, array $arguments): self
{
if (!isset(self::MAGIC_OPERATIONS[$methodName])) {
throw new Exception('Invalid Operation for Date Value CF Rule Wizard');
}View on GitHub (pinned to 65b080eef4)
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
Example fix
// before
$wizard = Wizard\DateValue::fromConditional($conditional); // throws unless type is timePeriod
// after
use PhpOffice\PhpSpreadsheet\Style\Conditional;
if ($conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD) {
$wizard = Wizard\DateValue::fromConditional($conditional);
} else {
$wizard = Wizard::fromConditional($conditional);
} Defensive patterns
Strategy: type-guard
Validate before calling
use PhpOffice\PhpSpreadsheet\Style\Conditional;
if ($conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD) {
$wizard = Wizard\DateValue::fromConditional($conditional, $cellRange);
} else {
$wizard = Wizard::fromConditional($conditional, $cellRange);
} Type guard
function isDateValueConditional(Conditional $conditional): bool
{
return $conditional->getConditionType() === Conditional::CONDITION_TIMEPERIOD;
} Try / catch
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
try {
$wizard = Wizard\DateValue::fromConditional($conditional, $cellRange);
} catch (PhpSpreadsheetException $e) {
$wizard = Wizard::fromConditional($conditional, $cellRange);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Conditional is not a Blanks CF Rule conditional
- Conditional is not a Cell Value CF Rule conditional
- Invalid Operation for Date Value CF Rule Wizard
- Conditional is not a Duplicates CF Rule conditional
- Conditional is not an Errors CF Rule conditional
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/213cb3f0bd7dbf91.
Report an issue: GitHub.