Beautiful Open-Source Form Builder
Add date field references to conditions with strict comparison validation (#1369)
Julien Nahumc3fa207142ab
diff --git a/README.md b/README.mdindex 17443b6b6..d0b90455b 100644--- a/README.md+++ b/README.md@@ -145,3 +145,23 @@ Run `vendor/bin/pest --filter=FormValidationTranslationsTest` from `api/` to che## Production performanceSee [runtime limits, caching and reproducible local measurements](docs/reports/production-performance-2026-10.md).++### Compare date fields in conditions++For a single date field's **Equals**, **Before**, **After**, **On or before**, or+**On or after** condition, choose **Fixed date** to use the calendar or+**Field or variable** to compare against another single date field or a computed+variable returning an ISO date. This works in+conditional logic and custom validation. Date ranges are excluded from reference+selection. Relative conditions such as **Within next X days** still take a number+of days. A comparison against an empty date does not pass.++Date operands are validated on the server when saving the form. References must+point to another existing single date field or a variable returning a date.+At evaluation, both runtimes reject nulls, empty strings, non-string values,+impossible dates, and non-ISO date text. Fields without time compare calendar dates, ignoring the time and offset carried+by the input. Fields with time compare instants with timezone offsets applied;+timezone-free values use UTC. Field references must have matching time settings.+Fractional seconds use millisecond precision in both runtimes. For fields with time, equality compares the instant, so timestamps with different+offsets can be equal. Optional empty+fields need an explicit **Is empty OR date comparison** rule if blanks should pass.diff --git a/api/app/Rules/CustomFieldValidationRule.php b/api/app/Rules/CustomFieldValidationRule.phpindex 90adf74b6..3cea59e98 100644--- a/api/app/Rules/CustomFieldValidationRule.php+++ b/api/app/Rules/CustomFieldValidationRule.php@@ -37,7 +37,7 @@ class CustomFieldValidationRule implements ValidationRulepublic function passes($attribute, $value){$logicConditions = $this->validation['error_conditions']['conditions'] ?? null;- if (empty($logicConditions) || empty($logicConditions['children'] ?? [])) {+ if (empty($logicConditions) || (is_array($logicConditions) && array_key_exists('children', $logicConditions) && $logicConditions['children'] === [])) {return true;}@@ -58,7 +58,7 @@ class CustomFieldValidationRule implements ValidationRule$formDataWithContext,$this->form);- } catch (\Exception $e) {+ } catch (\Throwable $e) {$this->errorOccurred = true;return false;}diff --git a/api/app/Rules/FormPropertiesRule.php b/api/app/Rules/FormPropertiesRule.phpindex 4c39ff839..121e3904a 100644--- a/api/app/Rules/FormPropertiesRule.php+++ b/api/app/Rules/FormPropertiesRule.php@@ -4,6 +4,7 @@ namespace App\Rules;use App\Models\Workspace;use App\Rules\PropertyValidators\CorePropertyValidator;+use App\Rules\PropertyValidators\DateComparisonPropertyValidator;use App\Rules\PropertyValidators\LogicPropertyValidator;use App\Rules\PropertyValidators\PaymentPropertyValidator;use App\Rules\PropertyValidators\PropertyValidatorInterface;@@ -46,6 +47,7 @@ class FormPropertiesRule implements ValidationRule, ValidatorAwareRule, DataAwarnew TypePropertyValidator(),new PaymentPropertyValidator($workspace),new LogicPropertyValidator(),+ new DateComparisonPropertyValidator(),new SelectOptionsPropertyValidator(),];}diff --git a/api/app/Rules/PropertyValidators/DateComparisonPropertyValidator.php b/api/app/Rules/PropertyValidators/DateComparisonPropertyValidator.phpnew file mode 100644index 000000000..80aaf0683--- /dev/null+++ b/api/app/Rules/PropertyValidators/DateComparisonPropertyValidator.php@@ -0,0 +1,82 @@+<?php++namespace App\Rules\PropertyValidators;++use App\Service\Forms\FormDateValue;++/** Validate date operands in both display logic and custom validation. */+class DateComparisonPropertyValidator implements PropertyValidatorInterface+{+ public function validate(array $property, int $index, array $context): array+ {+ $references = [];+ foreach ($context['properties'] ?? [] as $reference) {+ if (is_array($reference) && is_string($reference['id'] ?? null)) {+ $references[$reference['id']] = $reference;+ }+ }+ foreach ($context['computed_variables'] ?? [] as $variable) {+ if (is_array($variable) && is_string($variable['id'] ?? null)) {+ $references[$variable['id']] = array_merge($variable, ['type' => 'computed']);+ }+ }+ $errors = [];+ foreach ([+ 'logic.conditions' => $property['logic']['conditions'] ?? null,+ 'validation.error_conditions.conditions' => $property['validation']['error_conditions']['conditions'] ?? null,+ ] as $path => $conditions) {+ $count = 0;+ $this->validateDates($conditions, $path, $references, $errors, 0, $count);+ }++ return $errors;+ }++ private function validateDates(mixed $condition, string $path, array $references, array &$errors, int $depth, int &$count): void+ {+ if ($condition === null) {+ return;+ }+ if (! is_array($condition) || $depth > 10 || ++$count > 100) {+ $errors[$path] = 'The conditions are malformed or exceed the supported limits.';+ return;+ }+ if (isset($condition['children'])) {+ if (! is_array($condition['children'])) {+ $errors[$path] = 'Condition children must be an array.';+ return;+ }+ foreach ($condition['children'] as $i => $child) {+ $this->validateDates($child, $path.'.children.'.$i, $references, $errors, $depth + 1, $count);+ if ($count > 100) {+ break;+ }+ }+ return;+ }+ $conditionValue = $condition['value'] ?? null;+ if (! is_array($conditionValue) || ($conditionValue['property_meta']['type'] ?? null) !== 'date'+ || ! in_array($conditionValue['operator'] ?? null, ['equals', 'before', 'after', 'on_or_before', 'on_or_after'], true)) {+ return;+ }+ $value = $conditionValue['value'] ?? null;+ $errorPath = $path.'.value.value';+ if (FormDateValue::timestamp($value) !== null) {+ return;+ }+ if (! is_string($value) || ! preg_match('/\A\s*<span\b([^>]*)>[^<]*<\/span>\s*\z/s', $value, $span)+ || ! preg_match('/\bmention-field-id="([^"]+)"/', $span[1], $mention)) {+ $errors[$errorPath] = 'Choose a valid ISO date or a single date field or variable reference.';+ return;+ }+ $id = html_entity_decode($mention[1], ENT_QUOTES | ENT_HTML5, 'UTF-8');+ $reference = $references[$id] ?? null;+ $isField = ($reference['type'] ?? null) !== 'computed';+ $source = $references[$conditionValue['property_meta']['id'] ?? ''] ?? [];+ if ($reference === null || $id === ($conditionValue['property_meta']['id'] ?? null)+ || ($isField && (($reference['type'] ?? null) !== 'date' || ($reference['date_range'] ?? false) || (bool) ($source['with_time'] ?? false) !== (bool) ($reference['with_time'] ?? false)))+ || (! $isField && in_array($reference['result_type'] ?? 'auto', ['number', 'boolean'], true))) {+ $errors[$errorPath] = 'Choose another existing single date field or a variable returning an ISO date.';+ }+ }+}diff --git a/api/app/Service/Forms/FormDateValue.php b/api/app/Service/Forms/FormDateValue.phpnew file mode 100644index 000000000..b7ed0a2a1--- /dev/null+++ b/api/app/Service/Forms/FormDateValue.php@@ -0,0 +1,50 @@+<?php++namespace App\Service\Forms;++use DateTimeImmutable;+use DateTimeZone;++class FormDateValue+{+ public static function comparisonValue(mixed $value, bool $withTime): ?float+ {+ $timestamp = self::timestamp($value);+ if ($timestamp === null || $withTime) {+ return $timestamp;+ }++ // DateInput includes a time/offset even for calendar-only inputs.+ return self::timestamp(substr($value, 0, 10));+ }++ /** Strict ISO dates only; timezone-free values use UTC in both runtimes. */+ public static function timestamp(mixed $value): ?float+ {+ if (! is_string($value) || ! preg_match('/\A(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,6}))?)?(Z|[+-]\d{2}:\d{2})?)?\z/', $value, $parts)) {+ return null;+ }++ [$year, $month, $day] = [(int) $parts[1], (int) $parts[2], (int) $parts[3]];+ $hour = (int) ($parts[4] ?? 0);+ $minute = (int) ($parts[5] ?? 0);+ $second = (int) ($parts[6] ?? 0);+ $zone = $parts[8] ?? 'Z';+ if (! checkdate($month, $day, $year) || $hour > 23 || $minute > 59 || $second > 59) {+ return null;+ }+ $offset = 0;+ if ($zone !== 'Z') {+ $zoneHour = (int) substr($zone, 1, 2);+ $zoneMinute = (int) substr($zone, 4, 2);+ if ($zoneHour > 23 || $zoneMinute > 59) {+ return null;+ }+ $offset = ($zoneHour * 60 + $zoneMinute) * ($zone[0] === '-' ? -1 : 1);+ }+ $date = DateTimeImmutable::createFromFormat('!Y-m-d H:i:s', sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hour, $minute, $second), new DateTimeZone('UTC'));+ $milliseconds = (int) str_pad(substr($parts[7] ?? '', 0, 3), 3, '0');++ return $date === false ? null : ($date->getTimestamp() - $offset * 60) * 1000.0 + $milliseconds;+ }+}diff --git a/api/app/Service/Forms/FormLogicConditionChecker.php b/api/app/Service/Forms/FormLogicConditionChecker.phpindex 0552c8905..61150e967 100644--- a/api/app/Service/Forms/FormLogicConditionChecker.php+++ b/api/app/Service/Forms/FormLogicConditionChecker.php@@ -11,6 +11,8 @@ class FormLogicConditionChecker{private ?array $computedValues = null;+ private array $dateFields = [];+public function __construct(private ?array $conditions, private ?array $formData){}@@ -25,7 +27,16 @@ class FormLogicConditionChecker*/public static function conditionsMetWithForm(?array $conditions, array $formData, ?Form $form): bool{+ // Submission input must never override a declared computed variable.+ foreach ($form?->computed_variables ?? [] as $variable) {+ unset($formData[$variable['id']]);+ }$checker = new self($conditions, $formData);+ foreach ($form?->properties ?? [] as $property) {+ if (($property['type'] ?? null) === 'date') {+ $checker->dateFields[$property['id']] = $property;+ }+ }// If form has computed variables, evaluate themif ($form && !empty($form->computed_variables)) {@@ -49,14 +60,12 @@ class FormLogicConditionChecker*/private function getValue(string $fieldId){- // First check form data- if (isset($this->formData[$fieldId])) {- return $this->formData[$fieldId];+ if ($this->computedValues !== null && array_key_exists($fieldId, $this->computedValues)) {+ return $this->computedValues[$fieldId];}- // Then check computed variables- if ($this->computedValues !== null && isset($this->computedValues[$fieldId])) {- return $this->computedValues[$fieldId];+ if (isset($this->formData[$fieldId])) {+ return $this->formData[$fieldId];}return null;@@ -393,26 +402,6 @@ class FormLogicConditionCheckerreturn (float) $fieldValue <= (float) $condition['value'];}- private function checkBefore($condition, $fieldValue): bool- {- return $condition['value'] && $fieldValue && $fieldValue < $condition['value'];- }-- private function checkAfter($condition, $fieldValue): bool- {- return $condition['value'] && $fieldValue && $fieldValue > $condition['value'];- }-- private function checkOnOrBefore($condition, $fieldValue): bool- {- return $condition['value'] && $fieldValue && $fieldValue <= $condition['value'];- }-- private function checkOnOrAfter($condition, $fieldValue): bool- {- return $condition['value'] && $fieldValue && $fieldValue >= $condition['value'];- }-private function checkPastWeek($condition, $fieldValue): bool{if (!$fieldValue) {@@ -829,17 +818,24 @@ class FormLogicConditionCheckerprivate function dateConditionMet(array $propertyCondition, $value): bool{+ if (in_array($propertyCondition['operator'], ['equals', 'before', 'after', 'on_or_before', 'on_or_after'], true)) {+ $field = $this->dateFields[$propertyCondition['property_meta']['id'] ?? ''] ?? null;+ $withTime = $field !== null ? (bool) ($field['with_time'] ?? false) : (bool) ($propertyCondition['property_meta']['with_time'] ?? true);+ $left = FormDateValue::comparisonValue($value, $withTime);+ $right = FormDateValue::comparisonValue($propertyCondition['value'] ?? null, $withTime);+ if ($left === null || $right === null) {+ return false;+ }++ return match ($propertyCondition['operator']) {+ 'equals' => $left === $right,+ 'before' => $left < $right,+ 'after' => $left > $right,+ 'on_or_before' => $left <= $right,+ 'on_or_after' => $left >= $right,+ };+ }switch ($propertyCondition['operator']) {- case 'equals':- return $this->checkEquals($propertyCondition, $value);- case 'before':- return $this->checkBefore($propertyCondition, $value);- case 'after':- return $this->checkAfter($propertyCondition, $value);- case 'on_or_before':- return $this->checkOnOrBefore($propertyCondition, $value);- case 'on_or_after':- return $this->checkOnOrAfter($propertyCondition, $value);case 'at_least_x_days_ago':return $this->checkAtLeastXDaysAgo($propertyCondition, $value);case 'at_least_x_days_from_now':diff --git a/api/tests/Feature/Forms/DateComparisonValidationTest.php b/api/tests/Feature/Forms/DateComparisonValidationTest.phpnew file mode 100644index 000000000..ff02faf81--- /dev/null+++ b/api/tests/Feature/Forms/DateComparisonValidationTest.php@@ -0,0 +1,85 @@+<?php++it('enforces date references on submission even without browser validation', function ($start, $end, bool $valid) {+ $user = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, ['properties' => [+ ['id' => 'start', 'name' => 'Start', 'type' => 'date', 'required' => true],+ ['id' => 'end', 'name' => 'End', 'type' => 'date', 'required' => false, 'validation' => [+ 'error_message' => 'End must be on or after start.',+ 'error_conditions' => ['conditions' => ['operatorIdentifier' => 'and', 'children' => [+ ['identifier' => 'end', 'value' => ['property_meta' => ['id' => 'end', 'type' => 'date'],+ 'operator' => 'on_or_after', 'value' => '<span mention-field-id="start">Start</span>']],+ ]]],+ ]],+ ]]);+ $response = $this->postJson(route('forms.answer', $form->slug), ['start' => $start, 'end' => $end]);+ if ($valid) {+ $response->assertSuccessful();+ } else {+ $response->assertUnprocessable()->assertJsonValidationErrors('end');+ }+})->with([+ ['2026-10-30', '2026-10-31', true],+ ['2026-10-30', '2026-10-29', false],+ ['2026-10-30', null, false],+ [null, '2026-10-30', false],+ ['2026-10-30', [], false],+ ['2026-10-30', '2026-02-30', false],+ ['2026-10-30T12:00:00+02:00', '2026-10-30T10:00:00Z', true],+]);++it('rejects invalid date references when saving through the API', function () {+ $user = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, ['properties' => [+ ['id' => 'start', 'name' => 'Start', 'type' => 'date'],+ ['id' => 'end', 'name' => 'End', 'type' => 'date'],+ ]]);+ $payload = $form->toArray();+ $payload['properties'][1]['validation'] = [+ 'error_message' => 'Invalid end date.',+ 'error_conditions' => ['conditions' => ['operatorIdentifier' => 'and', 'children' => [+ ['identifier' => 'end', 'value' => ['property_meta' => ['id' => 'end', 'type' => 'date'],+ 'operator' => 'on_or_after', 'value' => '<span mention-field-id="deleted">Deleted</span>']],+ ]]],+ ];+ $this->putJson(route('open.forms.update', $form->id), $payload)+ ->assertUnprocessable()->assertJsonValidationErrors('properties.1.validation.error_conditions.conditions.children.0.value.value');+ $payload['properties'][1]['validation']['error_conditions']['conditions']['children'][0]['value']['value'] = '<span mention-field-id="start">Start</span>';+ $this->putJson(route('open.forms.update', $form->id), $payload)->assertSuccessful();+});++it('enforces a single leaf date validation condition', function () {+ $condition = ['value' => ['property_meta' => ['id' => 'end', 'type' => 'date'], 'operator' => 'on_or_after',+ 'value' => '<span mention-field-id="start">Start</span>']];+ $rule = new \App\Rules\CustomFieldValidationRule(['error_conditions' => ['conditions' => $condition]], ['start' => '2026-10-30', 'end' => '2026-10-29']);+ expect($rule->passes('end', '2026-10-29'))->toBeFalse();+});++it('does not trust submitted values for computed date references', function ($start, $end, $spoof, bool $valid) {+ $user = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'computed_variables' => [['id' => 'cv_start', 'name' => 'Computed start', 'formula' => '{start}', 'result_type' => 'auto']],+ 'properties' => [+ ['id' => 'start', 'name' => 'Start', 'type' => 'date', 'required' => false],+ ['id' => 'end', 'name' => 'End', 'type' => 'date', 'validation' => [+ 'error_conditions' => ['conditions' => ['operatorIdentifier' => 'and', 'children' => [+ ['identifier' => 'end', 'value' => ['property_meta' => ['id' => 'end', 'type' => 'date'], 'operator' => 'on_or_after',+ 'value' => '<span mention-field-id="cv_start">Computed start</span>']],+ ]]],+ ]],+ ],+ ]);+ $response = $this->postJson(route('forms.answer', $form->slug), ['start' => $start, 'end' => $end, 'cv_start' => $spoof]);+ if ($valid) {+ $response->assertSuccessful();+ } else {+ $response->assertUnprocessable()->assertJsonValidationErrors('end');+ }+})->with([+ ['2026-10-30', '2026-10-29', '2026-10-28', false],+ [null, '2026-10-29', '2026-10-28', false],+ ['2026-10-30', '2026-10-31', null, true],+]);diff --git a/api/tests/Unit/Rules/DateComparisonPropertyValidatorTest.php b/api/tests/Unit/Rules/DateComparisonPropertyValidatorTest.phpnew file mode 100644index 000000000..e7347f48c--- /dev/null+++ b/api/tests/Unit/Rules/DateComparisonPropertyValidatorTest.php@@ -0,0 +1,38 @@+<?php++use App\Rules\PropertyValidators\DateComparisonPropertyValidator;++function dateComparisonProperty($value, string $location): array+{+ $conditions = ['operatorIdentifier' => 'and', 'children' => [['identifier' => 'end', 'value' => [+ 'property_meta' => ['id' => 'end', 'type' => 'date'], 'operator' => 'on_or_after', 'value' => $value,+ ]]]];+ return $location === 'logic' ? ['logic' => ['conditions' => $conditions]]+ : ['validation' => ['error_conditions' => ['conditions' => $conditions]]];+}++it('validates date operands in display and validation rules', function ($value, bool $valid, string $location) {+ $context = ['properties' => [+ ['id' => 'start', 'type' => 'date'], ['id' => 'end', 'type' => 'date'],+ ['id' => 'range', 'type' => 'date', 'date_range' => true], ['id' => 'text', 'type' => 'text'],+ ], 'computed_variables' => [['id' => 'cv_date', 'result_type' => 'text'], ['id' => 'cv_num', 'result_type' => 'number']]];+ $errors = (new DateComparisonPropertyValidator())->validate(dateComparisonProperty($value, $location), 0, $context);+ expect($errors === [])->toBe($valid);+})->with([+ ['2026-10-30', true], ['2026-02-30', false], [null, false], [[], false],+ ['<span mention-field-id="start">Start</span>', true],+ ['<span mention-field-id="cv_date">Variable</span>', true],+ ['<span mention-field-id="cv_num">Variable</span>', false],+ ['<span mention-field-id="missing">Missing</span>', false],+ ['<span mention-field-id="end">Self</span>', false],+ ['<span mention-field-id="range">Range</span>', false],+ ['<span mention-field-id="text">Text</span>', false],+ ['prefix <span mention-field-id="start">Start</span>', false],+ ['<span mention-field-id="start">Start</span><span mention-field-id="end">End</span>', false],+])->with(['logic', 'validation']);++it('rejects mixed date-only and date-time field references', function () {+ $context = ['properties' => [['id' => 'start', 'type' => 'date', 'with_time' => true], ['id' => 'end', 'type' => 'date']]];+ $errors = (new DateComparisonPropertyValidator())->validate(dateComparisonProperty('<span mention-field-id="start">Start</span>', 'validation'), 0, $context);+ expect($errors)->not->toBeEmpty();+});diff --git a/api/tests/Unit/Service/Forms/DateComparisonTest.php b/api/tests/Unit/Service/Forms/DateComparisonTest.phpnew file mode 100644index 000000000..686db7482--- /dev/null+++ b/api/tests/Unit/Service/Forms/DateComparisonTest.php@@ -0,0 +1,30 @@+<?php++use App\Service\Forms\FormLogicConditionChecker;++it('compares strict ISO dates consistently with the frontend', function (array $case) {+ $condition = ['value' => [+ 'property_meta' => ['id' => 'end', 'type' => 'date', 'with_time' => $case['with_time'] ?? true],+ 'operator' => $case['operator'],+ 'value' => '<span mention="true" mention-field-id="start">Start</span>',+ ]];+ expect(FormLogicConditionChecker::conditionsMet($condition, ['end' => $case['left'], 'start' => $case['right']]))->toBe($case['expected']);+})->with(array_map(fn ($case) => [$case], json_decode(file_get_contents(dirname(__DIR__, 5).'/client/test/fixtures/date-comparisons.json'), true)));++it('resolves and validates computed date references and missing variables', function () {+ $form = new \App\Models\Forms\Form();+ $form->computed_variables = [['id' => 'cv_start', 'formula' => '{start}', 'result_type' => 'text']];+ $condition = ['value' => ['property_meta' => ['id' => 'end', 'type' => 'date'], 'operator' => 'on_or_after',+ 'value' => '<span mention-field-id="cv_start">Computed start</span>']];+ expect(FormLogicConditionChecker::conditionsMetWithForm($condition, ['start' => '2026-10-30', 'end' => '2026-10-31'], $form))->toBeTrue();+ expect(FormLogicConditionChecker::conditionsMetWithForm($condition, ['start' => 'invalid', 'end' => '2026-10-31'], $form))->toBeFalse();+ expect(FormLogicConditionChecker::conditionsMetWithForm($condition, ['end' => '2026-10-31'], $form))->toBeFalse();+});+++it('uses owning form date metadata instead of stale condition metadata', function () {+ $form = new \App\Models\Forms\Form();+ $form->properties = [['id' => 'end', 'type' => 'date', 'with_time' => false]];+ $condition = ['value' => ['property_meta' => ['id' => 'end', 'type' => 'date', 'with_time' => true], 'operator' => 'equals', 'value' => '2026-10-30T00:00:00-04:00']];+ expect(FormLogicConditionChecker::conditionsMetWithForm($condition, ['end' => '2026-10-30T00:00:00+01:00'], $form))->toBeTrue();+});diff --git a/client/components/open/forms/components/form-logic-components/ColumnCondition.vue b/client/components/open/forms/components/form-logic-components/ColumnCondition.vueindex c81ff6b90..0e908d204 100644--- a/client/components/open/forms/components/form-logic-components/ColumnCondition.vue+++ b/client/components/open/forms/components/form-logic-components/ColumnCondition.vue@@ -6,7 +6,7 @@<!-- Operator Selection --><USelectMenuv-model="content.operator"- class="w-[100px]"+ class="min-w-[100px] shrink-0":items="operators"value-key="value"placeholder="Operator"@@ -21,7 +21,31 @@<!-- Value Input (if needed) --><template v-if="needsInput">+ <USelectMenu+ v-if="supportsDateReference"+ :model-value="dateValueMode"+ :items="[{ label: 'Fixed date', value: 'fixed' }, { label: 'Field or variable', value: 'reference' }]"+ value-key="value"+ aria-label="Date comparison value type"+ size="sm"+ class="w-[135px] shrink-0"+ :search-input="false"+ @update:model-value="changeDateValueMode"+ />+ <USelectMenu+ v-if="supportsDateReference && dateValueMode === 'reference'"+ :model-value="dateReferenceId"+ :items="dateReferenceOptions"+ value-key="value"+ aria-label="Date comparison field or variable"+ placeholder="Choose a field or variable"+ size="sm"+ class="flex-1 min-w-[140px]"+ :search-input="{ placeholder: 'Search fields and variables...' }"+ @update:model-value="selectDateReference"+ /><component+ v-elsev-bind="inputComponentData":is="inputComponentData.component"v-model="content.value"@@ -38,6 +62,7 @@<script>import { defineAsyncComponent } from 'vue'+import { escapeHtml } from '~/lib/utils'import OpenFilters from "../../../../../data/open_filters.json"import {getConditionInputComponent,@@ -64,6 +89,7 @@ export default {content: this.modelValue ? { ...this.modelValue } : {},available_filters: OpenFilters,hasInput: false,+ dateValueMode: typeof this.modelValue?.value === 'string' && this.modelValue.value.includes('mention-field-id') ? 'reference' : 'fixed',}},@@ -80,6 +106,25 @@ export default {mentionComputedVariables() {return getMentionComputedVariables(this.formComputedVariables, this.property)},+ supportsDateReference() {+ return this.property.type === 'date' && !this.property.date_range &&+ this.selectedOperator()?.format?.type === 'date'+ },+ dateReferenceId() {+ return typeof this.content.value === 'string'+ ? this.content.value.match(/mention-field-id="([^"]+)"/)?.[1]+ : undefined+ },+ dateReferenceOptions() {+ return [+ ...this.mentionFields+ .filter(field => field.type === 'date' && !field.date_range && !!field.with_time === !!this.property.with_time)+ .map(field => ({ label: field.name, value: field.id, icon: 'i-heroicons-calendar-days' })),+ ...this.mentionComputedVariables+ .filter(variable => !['number', 'boolean'].includes(variable.result_type))+ .map(variable => ({ label: variable.name, value: variable.id, icon: 'i-heroicons-variable' })),+ ]+ },inputComponentData() {const componentData = {component: getConditionInputComponent(this.property),@@ -112,7 +157,15 @@ export default {if (["at_least_x_days_ago", "at_least_x_days_from_now", "within_past_x_days", "within_next_x_days"].includes(this.content.operator)) {componentData.component = "TextInput"}- // componentData.withTime = true+ if (componentData.component === 'DateInput') {+ componentData.withTime = this.property.with_time === true+ componentData.ui = {+ slots: {+ input: 'h-7 rounded-md',+ inner: 'py-1 text-sm/4',+ },+ }+ }} else if (this.property.type === "checkbox") {componentData.label = this.property.name}@@ -190,6 +243,17 @@ export default {},methods: {+ changeDateValueMode(mode) {+ this.dateValueMode = mode+ this.content.value = null+ this.emitInput()+ },+ selectDateReference(id) {+ const reference = this.dateReferenceOptions.find(option => option.value === id)+ if (!reference) return+ this.content.value = `<span mention="true" mention-field-id="${escapeHtml(id)}" mention-field-name="${escapeHtml(reference.label)}" mention-fallback="">${escapeHtml(reference.label)}</span>`+ this.emitInput()+ },castContent(content) {if (typeof content.value === 'string' && content.value.includes('mention-field-id')) {return content@@ -219,6 +283,12 @@ export default {const operator = this.selectedOperator()const operatorFormat = operator.format+ // Relative date operators expect a number of days, never a date reference.+ if (this.property.type === 'date' && !this.supportsDateReference && this.dateReferenceId) {+ this.content.value = null+ this.dateValueMode = 'fixed'+ }+if (operator.expected_type === "boolean" &&operatorFormat.type === "enum" &&@@ -271,12 +341,17 @@ export default {}}+ // Keep an empty reference selector open while editing; infer mode for saved values.+ if (modelValue.value) {+ this.dateValueMode = typeof modelValue.value === 'string' && modelValue.value.includes('mention-field-id') ? 'reference' : 'fixed'+ }this.content = {operator: this.operators[0]?.value,...modelValue,property_meta: {id: this.property.id,type: this.property.type,+ ...(this.property.type === 'date' ? { with_time: this.property.with_time === true } : {}),},}},diff --git a/client/lib/forms/FormLogicConditionChecker.js b/client/lib/forms/FormLogicConditionChecker.jsindex 7d28d1946..6ce3f1d2d 100644--- a/client/lib/forms/FormLogicConditionChecker.js+++ b/client/lib/forms/FormLogicConditionChecker.js@@ -1,3 +1,4 @@+import { compareDates } from './dateComparison.js'import { default as _isEqual } from "lodash/isEqual"const mentionSpanRegex = /<span\b(?=[^>]*\bmention\b)[^>]*>.*?<\/span>/gis@@ -52,7 +53,7 @@ function resolveConditionValue(value, formData) {return stripHtml(resolvedValue)}-export function conditionsMet(conditions, formData) {+export function conditionsMet(conditions, formData, properties = []) {if (conditions === undefined || conditions === null) {return false}@@ -62,7 +63,11 @@ export function conditionsMet(conditions, formData) {const condition = conditions.valueif (!condition) return false- const resolvedCondition = { ...condition }+ const field = properties.find(property => property.id === condition.property_meta?.id)+ const resolvedCondition = { ...condition, property_meta: {+ ...condition.property_meta,+ ...(field?.type === 'date' ? { with_time: field.with_time === true } : {}),+ } }if (resolvedCondition.value !== undefined && resolvedCondition.value !== null) {resolvedCondition.value = resolveConditionValue(resolvedCondition.value, formData)}@@ -77,7 +82,7 @@ export function conditionsMet(conditions, formData) {let isvalid = trueif (!Array.isArray(conditions.children) || conditions.children.length === 0) return falseconditions.children.forEach((childrenCondition) => {- if (!conditionsMet(childrenCondition, formData)) {+ if (!conditionsMet(childrenCondition, formData, properties)) {isvalid = false}})@@ -86,7 +91,7 @@ export function conditionsMet(conditions, formData) {let isvalid = falseif (!Array.isArray(conditions.children) || conditions.children.length === 0) return falseconditions.children.forEach((childrenCondition) => {- if (conditionsMet(childrenCondition, formData)) {+ if (conditionsMet(childrenCondition, formData, properties)) {isvalid = true}})@@ -249,22 +254,6 @@ function checkLessThanEqual(condition, fieldValue) {return parseFloat(fieldValue) <= parseFloat(condition.value)}-function checkBefore(condition, fieldValue) {- return condition.value && fieldValue && fieldValue < condition.value-}--function checkAfter(condition, fieldValue) {- return condition.value && fieldValue && fieldValue > condition.value-}--function checkOnOrBefore(condition, fieldValue) {- return condition.value && fieldValue && fieldValue <= condition.value-}--function checkOnOrAfter(condition, fieldValue) {- return condition.value && fieldValue && fieldValue >= condition.value-}-function checkPastWeek(condition, fieldValue) {if (!fieldValue) return falseconst fieldDate = new Date(fieldValue)@@ -518,17 +507,10 @@ function selectConditionMet(propertyCondition, value) {}function dateConditionMet(propertyCondition, value) {+ if (['equals', 'before', 'after', 'on_or_before', 'on_or_after'].includes(propertyCondition.operator)) {+ return compareDates(propertyCondition.operator, value, propertyCondition.value, propertyCondition.property_meta?.with_time ?? true)+ }switch (propertyCondition.operator) {- case "equals":- return checkEquals(propertyCondition, value)- case "before":- return checkBefore(propertyCondition, value)- case "after":- return checkAfter(propertyCondition, value)- case "on_or_before":- return checkOnOrBefore(propertyCondition, value)- case "on_or_after":- return checkOnOrAfter(propertyCondition, value)case 'at_least_x_days_ago':return checkAtLeastXDaysAgo(propertyCondition, value)case 'at_least_x_days_from_now':diff --git a/client/lib/forms/FormLogicPropertyResolver.js b/client/lib/forms/FormLogicPropertyResolver.jsindex ee2005e57..7b10a5679 100644--- a/client/lib/forms/FormLogicPropertyResolver.js+++ b/client/lib/forms/FormLogicPropertyResolver.js@@ -5,7 +5,8 @@ class FormLogicPropertyResolver {formData = nulllogic = false- constructor(property, formData) {+ constructor(property, formData, properties = []) {+ this.properties = propertiesthis.property = propertythis.formData = formDatathis.logic = property.logic !== undefined ? property.logic : false@@ -19,6 +20,7 @@ class FormLogicPropertyResolver {const conditionsMet = this.conditionsMet(this.logic.conditions,this.formData,+ this.properties,)if (conditionsMet &&@@ -47,6 +49,7 @@ class FormLogicPropertyResolver {const conditionsMet = this.conditionsMet(this.logic.conditions,this.formData,+ this.properties,)if (conditionsMet &&@@ -75,6 +78,7 @@ class FormLogicPropertyResolver {const conditionsMet = this.conditionsMet(this.logic.conditions,this.formData,+ this.properties,)if (conditionsMet &&diff --git a/client/lib/forms/composables/useFieldState.js b/client/lib/forms/composables/useFieldState.jsindex 71e1d3287..10bfe533c 100644--- a/client/lib/forms/composables/useFieldState.js+++ b/client/lib/forms/composables/useFieldState.js@@ -16,7 +16,7 @@ export function useFieldState(formDataRef, formRef, strategyRef, computedValuesR...(toValue(formDataRef) || {}),...(toValue(computedValuesRef) || {})}- const resolver = new FormLogicPropertyResolver(field, currentData)+ const resolver = new FormLogicPropertyResolver(field, currentData, toValue(formRef)?.properties || [])return {hidden: !!resolver.isHidden(),required: !!resolver.isRequired(),diff --git a/client/lib/forms/dateComparison.js b/client/lib/forms/dateComparison.jsnew file mode 100644index 000000000..2c7158914--- /dev/null+++ b/client/lib/forms/dateComparison.js@@ -0,0 +1,39 @@+// Keep in sync with the backend FormDateValue parser. Never coerce empty values.+export function dateTimestamp(value) {+ if (typeof value !== 'string') return null+ const parts = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,6}))?)?(Z|[+-]\d{2}:\d{2})?)?$/.exec(value)+ if (!parts || parts[0] !== value) return null+ const [, y, m, d, h = '0', min = '0', s = '0', fraction = '', zone = 'Z'] = parts+ const [year, month, day, hour, minute, second] = [y, m, d, h, min, s].map(Number)+ if (year < 1 || month < 1 || month > 12 || day < 1 || hour > 23 || minute > 59 || second > 59) return null+ const date = new Date(0)+ date.setUTCFullYear(year, month - 1, day)+ date.setUTCHours(hour, minute, second, Number(fraction.slice(0, 3).padEnd(3, '0')))+ if (date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return null+ let offset = 0+ if (zone !== 'Z') {+ const zoneHour = Number(zone.slice(1, 3))+ const zoneMinute = Number(zone.slice(4, 6))+ if (zoneHour > 23 || zoneMinute > 59) return null+ offset = (zoneHour * 60 + zoneMinute) * (zone[0] === '-' ? -1 : 1)+ }+ return date.getTime() - offset * 60000+}++export function compareDates(operator, left, right, withTime = true) {+ let a = dateTimestamp(left)+ let b = dateTimestamp(right)+ if (!withTime && a !== null && b !== null) {+ a = dateTimestamp(left.slice(0, 10))+ b = dateTimestamp(right.slice(0, 10))+ }+ if (a === null || b === null) return false+ switch (operator) {+ case 'equals': return a === b+ case 'before': return a < b+ case 'after': return a > b+ case 'on_or_before': return a <= b+ case 'on_or_after': return a >= b+ default: return false+ }+}diff --git a/client/test/fixtures/date-comparisons.json b/client/test/fixtures/date-comparisons.jsonnew file mode 100644index 000000000..827165f3e--- /dev/null+++ b/client/test/fixtures/date-comparisons.json@@ -0,0 +1,193 @@+[+ {"left": null, "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": null, "operator": "equals", "expected": false},+ {"left": null, "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": null, "operator": "before", "expected": false},+ {"left": null, "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": null, "operator": "after", "expected": false},+ {"left": null, "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": null, "operator": "on_or_before", "expected": false},+ {"left": null, "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": null, "operator": "on_or_after", "expected": false},+ {"left": "", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "", "operator": "equals", "expected": false},+ {"left": "", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "", "operator": "before", "expected": false},+ {"left": "", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "", "operator": "after", "expected": false},+ {"left": "", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "", "operator": "on_or_before", "expected": false},+ {"left": "", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "", "operator": "on_or_after", "expected": false},+ {"left": 0, "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": 0, "operator": "equals", "expected": false},+ {"left": 0, "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": 0, "operator": "before", "expected": false},+ {"left": 0, "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": 0, "operator": "after", "expected": false},+ {"left": 0, "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": 0, "operator": "on_or_before", "expected": false},+ {"left": 0, "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": 0, "operator": "on_or_after", "expected": false},+ {"left": false, "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": false, "operator": "equals", "expected": false},+ {"left": false, "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": false, "operator": "before", "expected": false},+ {"left": false, "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": false, "operator": "after", "expected": false},+ {"left": false, "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": false, "operator": "on_or_before", "expected": false},+ {"left": false, "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": false, "operator": "on_or_after", "expected": false},+ {"left": [], "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": [], "operator": "equals", "expected": false},+ {"left": [], "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": [], "operator": "before", "expected": false},+ {"left": [], "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": [], "operator": "after", "expected": false},+ {"left": [], "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": [], "operator": "on_or_before", "expected": false},+ {"left": [], "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": [], "operator": "on_or_after", "expected": false},+ {"left": {}, "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": {}, "operator": "equals", "expected": false},+ {"left": {}, "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": {}, "operator": "before", "expected": false},+ {"left": {}, "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": {}, "operator": "after", "expected": false},+ {"left": {}, "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": {}, "operator": "on_or_before", "expected": false},+ {"left": {}, "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": {}, "operator": "on_or_after", "expected": false},+ {"left": ["2026-10-30"], "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": ["2026-10-30"], "operator": "equals", "expected": false},+ {"left": ["2026-10-30"], "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": ["2026-10-30"], "operator": "before", "expected": false},+ {"left": ["2026-10-30"], "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": ["2026-10-30"], "operator": "after", "expected": false},+ {"left": ["2026-10-30"], "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": ["2026-10-30"], "operator": "on_or_before", "expected": false},+ {"left": ["2026-10-30"], "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": ["2026-10-30"], "operator": "on_or_after", "expected": false},+ {"left": "not a date", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "not a date", "operator": "equals", "expected": false},+ {"left": "not a date", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "not a date", "operator": "before", "expected": false},+ {"left": "not a date", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "not a date", "operator": "after", "expected": false},+ {"left": "not a date", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "not a date", "operator": "on_or_before", "expected": false},+ {"left": "not a date", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "not a date", "operator": "on_or_after", "expected": false},+ {"left": "2026-02-30", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-02-30", "operator": "equals", "expected": false},+ {"left": "2026-02-30", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-02-30", "operator": "before", "expected": false},+ {"left": "2026-02-30", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-02-30", "operator": "after", "expected": false},+ {"left": "2026-02-30", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-02-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-02-30", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-02-30", "operator": "on_or_after", "expected": false},+ {"left": "2025-02-29", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2025-02-29", "operator": "equals", "expected": false},+ {"left": "2025-02-29", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2025-02-29", "operator": "before", "expected": false},+ {"left": "2025-02-29", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2025-02-29", "operator": "after", "expected": false},+ {"left": "2025-02-29", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2025-02-29", "operator": "on_or_before", "expected": false},+ {"left": "2025-02-29", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2025-02-29", "operator": "on_or_after", "expected": false},+ {"left": "2026-13-01", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-13-01", "operator": "equals", "expected": false},+ {"left": "2026-13-01", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-13-01", "operator": "before", "expected": false},+ {"left": "2026-13-01", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-13-01", "operator": "after", "expected": false},+ {"left": "2026-13-01", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-13-01", "operator": "on_or_before", "expected": false},+ {"left": "2026-13-01", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-13-01", "operator": "on_or_after", "expected": false},+ {"left": "2026-01-00", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-01-00", "operator": "equals", "expected": false},+ {"left": "2026-01-00", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-01-00", "operator": "before", "expected": false},+ {"left": "2026-01-00", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-01-00", "operator": "after", "expected": false},+ {"left": "2026-01-00", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-01-00", "operator": "on_or_before", "expected": false},+ {"left": "2026-01-00", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-01-00", "operator": "on_or_after", "expected": false},+ {"left": "0000-01-01", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "0000-01-01", "operator": "equals", "expected": false},+ {"left": "0000-01-01", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "0000-01-01", "operator": "before", "expected": false},+ {"left": "0000-01-01", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "0000-01-01", "operator": "after", "expected": false},+ {"left": "0000-01-01", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "0000-01-01", "operator": "on_or_before", "expected": false},+ {"left": "0000-01-01", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "0000-01-01", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30T24:00:00Z", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T24:00:00Z", "operator": "equals", "expected": false},+ {"left": "2026-10-30T24:00:00Z", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T24:00:00Z", "operator": "before", "expected": false},+ {"left": "2026-10-30T24:00:00Z", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T24:00:00Z", "operator": "after", "expected": false},+ {"left": "2026-10-30T24:00:00Z", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T24:00:00Z", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30T24:00:00Z", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T24:00:00Z", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30T10:60:00Z", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:60:00Z", "operator": "equals", "expected": false},+ {"left": "2026-10-30T10:60:00Z", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:60:00Z", "operator": "before", "expected": false},+ {"left": "2026-10-30T10:60:00Z", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:60:00Z", "operator": "after", "expected": false},+ {"left": "2026-10-30T10:60:00Z", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:60:00Z", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30T10:60:00Z", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:60:00Z", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30T10:00:00+24:00", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:00:00+24:00", "operator": "equals", "expected": false},+ {"left": "2026-10-30T10:00:00+24:00", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:00:00+24:00", "operator": "before", "expected": false},+ {"left": "2026-10-30T10:00:00+24:00", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:00:00+24:00", "operator": "after", "expected": false},+ {"left": "2026-10-30T10:00:00+24:00", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:00:00+24:00", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30T10:00:00+24:00", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30T10:00:00+24:00", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30\n", "right": "2026-10-30", "operator": "equals", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30\n", "operator": "equals", "expected": false},+ {"left": "2026-10-30\n", "right": "2026-10-30", "operator": "before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30\n", "operator": "before", "expected": false},+ {"left": "2026-10-30\n", "right": "2026-10-30", "operator": "after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30\n", "operator": "after", "expected": false},+ {"left": "2026-10-30\n", "right": "2026-10-30", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30\n", "operator": "on_or_before", "expected": false},+ {"left": "2026-10-30\n", "right": "2026-10-30", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30", "right": "2026-10-30\n", "operator": "on_or_after", "expected": false},+ {"left": "2026-10-30T12:00:00+02:00", "right": "2026-10-30T10:00:00Z", "operator": "equals", "expected": true},+ {"left": "2026-10-30T12:00:00+02:00", "right": "2026-10-30T10:00:00Z", "operator": "before", "expected": false},+ {"left": "2026-10-30T12:00:00+02:00", "right": "2026-10-30T10:00:00Z", "operator": "after", "expected": false},+ {"left": "2026-10-30T12:00:00+02:00", "right": "2026-10-30T10:00:00Z", "operator": "on_or_before", "expected": true},+ {"left": "2026-10-30T12:00:00+02:00", "right": "2026-10-30T10:00:00Z", "operator": "on_or_after", "expected": true},+ {"left": "2026-10-30T00:15:00+02:00", "right": "2026-10-29T23:30:00Z", "operator": "before", "expected": true},+ {"left": "2026-10-30T10:00:00.123456Z", "right": "2026-10-30T10:00:00.123Z", "operator": "equals", "expected": true},+ {"left": "2024-02-29", "right": "2024-03-01", "operator": "before", "expected": true},+ {"left": "2026-10-30", "right": "2026-10-30T00:00:00Z", "operator": "equals", "expected": true},+ {"left": "2026-10-30 10:00", "right": "2026-10-30T10:00:00Z", "operator": "equals", "expected": true},+ {"left": "2026-10-30T00:00:00+01:00", "right": "2026-10-30T00:00:00-04:00", "operator": "equals", "expected": true, "with_time": false},+ {"left": "2026-03-29T00:00:00+01:00", "right": "2026-03-29T00:00:00+02:00", "operator": "equals", "expected": true, "with_time": false},+ {"left": "2026-10-30T00:00:00+01:00", "right": "2026-10-30T00:00:00-04:00", "operator": "before", "expected": false, "with_time": false},+ {"left": "2026-03-29T00:00:00+01:00", "right": "2026-03-29T00:00:00+02:00", "operator": "before", "expected": false, "with_time": false},+ {"left": "2026-10-30T00:00:00+01:00", "right": "2026-10-30T00:00:00-04:00", "operator": "after", "expected": false, "with_time": false},+ {"left": "2026-03-29T00:00:00+01:00", "right": "2026-03-29T00:00:00+02:00", "operator": "after", "expected": false, "with_time": false},+ {"left": "2026-10-30T00:00:00+01:00", "right": "2026-10-30T00:00:00-04:00", "operator": "on_or_before", "expected": true, "with_time": false},+ {"left": "2026-03-29T00:00:00+01:00", "right": "2026-03-29T00:00:00+02:00", "operator": "on_or_before", "expected": true, "with_time": false},+ {"left": "2026-10-30T00:00:00+01:00", "right": "2026-10-30T00:00:00-04:00", "operator": "on_or_after", "expected": true, "with_time": false},+ {"left": "2026-03-29T00:00:00+01:00", "right": "2026-03-29T00:00:00+02:00", "operator": "on_or_after", "expected": true, "with_time": false},+ {"left": "2026-10-30T00:15:00+02:00", "right": "2026-10-29T23:30:00Z", "operator": "after", "expected": true, "with_time": false}+]diff --git a/client/test/nuxt/column-condition.component.spec.ts b/client/test/nuxt/column-condition.component.spec.tsindex 1f4cec9a3..0829406a6 100644--- a/client/test/nuxt/column-condition.component.spec.ts+++ b/client/test/nuxt/column-condition.component.spec.ts@@ -70,6 +70,7 @@ function mountColumnCondition({MentionInput: mentionInputStub,TextInput: { name: 'TextInput', inheritAttrs: false, props: ['modelValue'], emits: ['update:modelValue'], template: '<input />' },PhoneInput: true,+ DateInput: true,},},})@@ -131,3 +132,70 @@ describe('ColumnCondition phone regex patterns', () => {wrapper.unmount()})})++describe('ColumnCondition date references', () => {+ const start = { id: 'start', name: 'Start date', type: 'date' }+ const end = { id: 'end', name: 'End date', type: 'date' }+ function mountDate(value: any = '2026-10-30') {+ return mountColumnCondition({+ property: end as any,+ formProperties: [start, end, { id: 'range', name: 'Range', type: 'date', date_range: true }, emailField] as any,+ formComputedVariables: [totalVariable, { id: 'cv_date', name: 'Computed date', result_type: 'text' }],+ modelValue: { operator: 'on_or_after', value },+ })+ }++ it('switches from a fixed date to a reference and restores saved references', async () => {+ const wrapper = mountDate()+ expect(wrapper.vm.dateValueMode).toBe('fixed')+ wrapper.vm.changeDateValueMode('reference')+ wrapper.vm.selectDateReference('start')+ await flushPromises()+ const saved = wrapper.emitted('update:modelValue')?.at(-1)?.[0] as any+ expect(saved.value).toContain('mention-field-id="start"')+ const restored = mountDate(saved.value)+ expect(restored.vm.dateValueMode).toBe('reference')+ expect(restored.vm.dateReferenceId).toBe('start')+ wrapper.vm.changeDateValueMode('fixed')+ expect(wrapper.vm.content.value).toBeNull()+ wrapper.unmount()+ restored.unmount()+ })++ it('offers other single date fields and non-numeric variables', () => {+ const wrapper = mountDate()+ expect(wrapper.vm.dateReferenceOptions.map((option: any) => option.value)).toEqual(['start', 'cv_date'])+ wrapper.unmount()+ })++ it('clears a date reference when switching to a relative day count', async () => {+ const wrapper = mountDate()+ wrapper.vm.changeDateValueMode('reference')+ wrapper.vm.selectDateReference('start')+ wrapper.vm.content.operator = 'within_next_x_days'+ await flushPromises()+ expect(wrapper.vm.supportsDateReference).toBe(false)+ expect(wrapper.vm.content.value).toBeNull()+ expect(wrapper.vm.inputComponentData.component).toBe('TextInput')+ wrapper.unmount()+ })+})++describe('date condition time settings', () => {+ it('offers matching date-time references and enables time in the fixed date picker', () => {+ const wrapper = mountColumnCondition({+ property: { id: 'end', name: 'End', type: 'date', with_time: true } as any,+ formProperties: [+ { id: 'start', name: 'Start', type: 'date', with_time: true },+ { id: 'day', name: 'Day', type: 'date' },+ ] as any,+ formComputedVariables: [],+ modelValue: { operator: 'on_or_after', value: null },+ })+ expect(wrapper.vm.dateReferenceOptions.map((option: any) => option.value)).toEqual(['start'])+ expect(wrapper.vm.inputComponentData.withTime).toBe(true)+ wrapper.vm.selectDateReference('start')+ expect(wrapper.emitted('update:modelValue')?.at(-1)?.[0]).toMatchObject({ property_meta: { with_time: true } })+ wrapper.unmount()+ })+})diff --git a/client/test/unit/FormLogicConditionChecker.test.ts b/client/test/unit/FormLogicConditionChecker.test.tsindex 9a7336f84..6677deb86 100644--- a/client/test/unit/FormLogicConditionChecker.test.ts+++ b/client/test/unit/FormLogicConditionChecker.test.ts@@ -121,3 +121,21 @@ describe('FormLogicConditionChecker mention values', () => {})).toBe(true)})})++describe('date field comparison references', () => {+ it.each([+ ['2026-10-31', '2026-10-30', true],+ ['2026-10-30', '2026-10-30', true],+ ['2026-10-29', '2026-10-30', false],+ ['2027-01-01', '2026-12-31', true],+ ['', '2026-10-30', false],+ ['2026-10-30', '', false],+ ])('checks end %s against start %s', (end, start, expected) => {+ const condition = { value: {+ property_meta: { id: 'end', type: 'date' },+ operator: 'on_or_after',+ value: '<span mention="true" mention-field-id="start" mention-field-name="Start" mention-fallback="">Start</span>',+ } }+ expect(Boolean(conditionsMet(condition, { start, end }))).toBe(expected)+ })+})diff --git a/client/test/unit/dateComparison.test.ts b/client/test/unit/dateComparison.test.tsnew file mode 100644index 000000000..cb341f63e--- /dev/null+++ b/client/test/unit/dateComparison.test.ts@@ -0,0 +1,18 @@+import { describe, expect, it } from 'vitest'+import cases from '../fixtures/date-comparisons.json'+import { conditionsMet } from '../../lib/forms/FormLogicConditionChecker.js'++describe('strict date comparisons', () => {+ it.each(cases)('compares $left $operator $right', ({ left, right, operator, expected, with_time = true }) => {+ const condition = { value: { property_meta: { id: 'end', type: 'date', with_time }, operator,+ value: '<span mention="true" mention-field-id="start">Start</span>',+ } }+ expect(conditionsMet(condition, { end: left, start: right })).toBe(expected)+ })+})+++it('uses owning field metadata over stale condition metadata', () => {+ const condition = { value: { property_meta: { id: 'end', type: 'date', with_time: true }, operator: 'equals', value: '2026-10-30T00:00:00-04:00' } }+ expect(conditionsMet(condition, { end: '2026-10-30T00:00:00+01:00' }, [{ id: 'end', type: 'date', with_time: false }])).toBe(true)+})