Beautiful Open-Source Form Builder
Add X days before/after conditions to FormLogicConditionChecker and u… (#881)
Chirag Chhatralad3d9c215e26a
diff --git a/api/app/Service/Forms/FormLogicConditionChecker.php b/api/app/Service/Forms/FormLogicConditionChecker.phpindex 9af781c4e..430e7788d 100644--- a/api/app/Service/Forms/FormLogicConditionChecker.php+++ b/api/app/Service/Forms/FormLogicConditionChecker.php@@ -285,6 +285,124 @@ class FormLogicConditionCheckerreturn $fieldDate >= now()->toDateString() && $fieldDate <= now()->addYears(1)->toDateString();}+ private function checkAtLeastXDaysAgo($condition, $fieldValue): bool+ {+ if (!$fieldValue || !$condition['value']) {+ return false;+ }++ // Validate date is valid+ $timestamp = strtotime($fieldValue);+ if ($timestamp === false) {+ return false;+ }+ $fieldDate = date('Y-m-d', $timestamp);++ // Validate days is a valid positive number+ if (!is_numeric($condition['value'])) {+ return false;+ }+ $daysBefore = (int) $condition['value'];+ if ($daysBefore < 0) {+ return false;+ }++ // Create target date by subtracting days from today+ $targetDate = now()->subDays($daysBefore)->toDateString();++ // Return true if fieldDate is on or before the target date (X days before today)+ return $fieldDate <= $targetDate;+ }++ private function checkAtLeastXDaysFromNow($condition, $fieldValue): bool+ {+ if (!$fieldValue || !$condition['value']) {+ return false;+ }++ // Validate date is valid+ $timestamp = strtotime($fieldValue);+ if ($timestamp === false) {+ return false;+ }+ $fieldDate = date('Y-m-d', $timestamp);++ // Validate days is a valid positive number+ if (!is_numeric($condition['value'])) {+ return false;+ }+ $daysAfter = (int) $condition['value'];+ if ($daysAfter < 0) {+ return false;+ }++ // Create target date by adding days to today+ $targetDate = now()->addDays($daysAfter)->toDateString();++ // Return true if fieldDate is on or after the target date (X days after today)+ return $fieldDate >= $targetDate;+ }++ private function checkWithinPastXDays($condition, $fieldValue): bool+ {+ if (!$fieldValue || !$condition['value']) {+ return false;+ }++ // Validate date is valid+ $timestamp = strtotime($fieldValue);+ if ($timestamp === false) {+ return false;+ }+ $fieldDate = date('Y-m-d', $timestamp);++ // Validate days is a valid positive number+ if (!is_numeric($condition['value'])) {+ return false;+ }+ $daysBefore = (int) $condition['value'];+ if ($daysBefore < 0) {+ return false;+ }++ // Create target date by subtracting days from today+ $targetDate = now()->subDays($daysBefore)->toDateString();+ $today = now()->toDateString();++ // Return true if fieldDate is between target date (X days ago) and today (inclusive)+ return $fieldDate >= $targetDate && $fieldDate <= $today;+ }++ private function checkWithinNextXDays($condition, $fieldValue): bool+ {+ if (!$fieldValue || !$condition['value']) {+ return false;+ }++ // Validate date is valid+ $timestamp = strtotime($fieldValue);+ if ($timestamp === false) {+ return false;+ }+ $fieldDate = date('Y-m-d', $timestamp);++ // Validate days is a valid positive number+ if (!is_numeric($condition['value'])) {+ return false;+ }+ $daysAfter = (int) $condition['value'];+ if ($daysAfter < 0) {+ return false;+ }++ // Create target date by adding days to today+ $targetDate = now()->addDays($daysAfter)->toDateString();+ $today = now()->toDateString();++ // Return true if fieldDate is between today and target date (X days from now) (inclusive)+ return $fieldDate >= $today && $fieldDate <= $targetDate;+ }+private function checkLength($condition, $fieldValue, $operator = '==='): bool{if (!$fieldValue || strlen($fieldValue) === 0) {@@ -494,6 +612,14 @@ class FormLogicConditionCheckerreturn $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':+ return $this->checkAtLeastXDaysFromNow($propertyCondition, $value);+ case 'within_past_x_days':+ return $this->checkWithinPastXDays($propertyCondition, $value);+ case 'within_next_x_days':+ return $this->checkWithinNextXDays($propertyCondition, $value);case 'is_empty':return $this->checkIsEmpty($propertyCondition, $value);case 'past_week':diff --git a/api/resources/data/open_filters.json b/api/resources/data/open_filters.jsonindex 2e65e3ed5..02115e52d 100644--- a/api/resources/data/open_filters.json+++ b/api/resources/data/open_filters.json@@ -719,6 +719,30 @@"type": "date"}},+ "at_least_x_days_ago": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },+ "at_least_x_days_from_now": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },+ "within_past_x_days": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },+ "within_next_x_days": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },"is_empty": {"expected_type": "boolean","format": {diff --git a/api/tests/Feature/Forms/FormLogicTest.php b/api/tests/Feature/Forms/FormLogicTest.phpindex 35b69a7cd..8c674f420 100644--- a/api/tests/Feature/Forms/FormLogicTest.php+++ b/api/tests/Feature/Forms/FormLogicTest.php@@ -695,3 +695,629 @@ it('cannot submit form with failed does_not_exist_in_submissions validation cond'message' => $validationMessage,]);});++it('can submit form with at_least_x_days_ago date logic condition when date is within range', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'at_least_x_days_ago',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '5',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 7 days before today (should trigger the logic)+ $testDate = now()->subDays(7)->format('Y-m-d');+ $formData = [+ 'date_field' => $testDate,+ 'title' => 'Required field filled',+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('cannot submit form with at_least_x_days_ago date logic when required field is missing', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'at_least_x_days_ago',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '5',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 7 days before today but missing the required field+ $testDate = now()->subDays(7)->format('Y-m-d');+ $formData = [+ 'date_field' => $testDate,+ // Missing 'title' field which should be required due to logic+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertStatus(422)+ ->assertJson([+ 'message' => 'The Name field is required.',+ 'errors' => [+ 'title' => [+ 'The Name field is required.',+ ],+ ],+ ]);+});++it('can submit form with at_least_x_days_from_now date logic condition when date is within range', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'at_least_x_days_from_now',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '5',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 7 days after today (should trigger the logic)+ $testDate = now()->addDays(7)->format('Y-m-d');+ $formData = [+ 'date_field' => $testDate,+ 'title' => 'Required field filled',+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('cannot submit form with at_least_x_days_from_now date logic when required field is missing', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'at_least_x_days_from_now',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '5',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 7 days after today but missing the required field+ $testDate = now()->addDays(7)->format('Y-m-d');+ $formData = [+ 'date_field' => $testDate,+ // Missing 'title' field which should be required due to logic+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertStatus(422)+ ->assertJson([+ 'message' => 'The Name field is required.',+ 'errors' => [+ 'title' => [+ 'The Name field is required.',+ ],+ ],+ ]);+});++it('can submit form with within_past_x_days date logic condition when date is within range', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_past_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '7',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 3 days before today (within the 7 day range - should trigger)+ $testDate = now()->subDays(3)->toDateString();+ $formData = [+ 'date_field' => $testDate,+ 'title' => 'Required field filled',+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('cannot submit form with within_past_x_days date logic when date is outside range', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_past_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '7',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 10 days before today (outside the 7 day range - should NOT trigger)+ $testDate = now()->subDays(10)->toDateString();+ $formData = [+ 'date_field' => $testDate,+ // No title field since logic should not trigger+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});+++it('can submit form with within_next_x_days date logic condition when date is within range', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_next_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '7',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 3 days after today (within the 7 day range - should trigger)+ $testDate = now()->addDays(3)->toDateString();+ $formData = [+ 'date_field' => $testDate,+ 'title' => 'Required field filled',+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('cannot submit form with within_next_x_days date logic when date is outside range', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_next_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '7',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with a date that is 10 days after today (outside the 7 day range - should NOT trigger)+ $testDate = now()->addDays(10)->toDateString();+ $formData = [+ 'date_field' => $testDate,+ // No title field since logic should not trigger+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('validates within_past_x_days includes today', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_past_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '7',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with today's date (should trigger since range includes today)+ $testDate = now()->toDateString();+ $formData = [+ 'date_field' => $testDate,+ 'title' => 'Required field filled',+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('validates within_next_x_days includes today', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_next_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => '7',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // Test with today's date (should trigger since range includes today)+ $testDate = now()->toDateString();+ $formData = [+ 'date_field' => $testDate,+ 'title' => 'Required field filled',+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});++it('validates date logic properly rejects invalid numeric condition values', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'properties' => [+ [+ 'id' => 'date_field',+ 'name' => 'Event Date',+ 'type' => 'date',+ 'hidden' => false,+ 'required' => true,+ ],+ [+ 'id' => 'title',+ 'name' => 'Name',+ 'type' => 'title',+ 'hidden' => false,+ 'required' => false,+ 'logic' => [+ 'conditions' => [+ 'operatorIdentifier' => 'and',+ 'children' => [+ [+ 'identifier' => 'date_field',+ 'value' => [+ 'operator' => 'within_past_x_days',+ 'property_meta' => [+ 'id' => 'date_field',+ 'type' => 'date',+ ],+ 'value' => 'abc',+ ],+ ],+ ],+ ],+ 'actions' => ['require-answer'],+ ],+ ],+ ],+ ]);++ // With invalid condition value, logic should not trigger (returns false)+ // So the title field should NOT be required+ $testDate = now()->subDays(3)->toDateString();+ $formData = [+ 'date_field' => $testDate,+ // No title field - logic should not trigger for invalid condition values+ ];++ $this->postJson(route('forms.answer', $form->slug), $formData)+ ->assertSuccessful()+ ->assertJson([+ 'type' => 'success',+ 'message' => 'Form submission saved.',+ ]);+});diff --git a/client/components/open/forms/components/form-logic-components/ColumnCondition.vue b/client/components/open/forms/components/form-logic-components/ColumnCondition.vueindex 5e781af9e..76c86b36f 100644--- a/client/components/open/forms/components/form-logic-components/ColumnCondition.vue+++ b/client/components/open/forms/components/form-logic-components/ColumnCondition.vue@@ -37,10 +37,16 @@</template><script>+import { defineAsyncComponent } from 'vue'import OpenFilters from "../../../../../data/open_filters.json"export default {- components: {},+ components: {+ DateInput: defineAsyncComponent(() => import('~/components/forms/heavy/DateInput.vue')),+ FileInput: defineAsyncComponent(() => import('~/components/forms/heavy/FileInput.vue')),+ MatrixInput: defineAsyncComponent(() => import('~/components/forms/heavy/MatrixInput.vue')),+ PhoneInput: defineAsyncComponent(() => import('~/components/forms/heavy/PhoneInput.vue'))+ },props: {modelValue: { type: Object, required: false, default: null },customValidation: { type: Boolean, default: false },@@ -101,6 +107,10 @@ export default {},)} else if (this.property.type === "date") {+ // For date range operators, use number input instead of date input+ 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} else if (this.property.type === "checkbox") {componentData.label = this.property.namediff --git a/client/data/open_filters.json b/client/data/open_filters.jsonindex 2e65e3ed5..02115e52d 100644--- a/client/data/open_filters.json+++ b/client/data/open_filters.json@@ -719,6 +719,30 @@"type": "date"}},+ "at_least_x_days_ago": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },+ "at_least_x_days_from_now": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },+ "within_past_x_days": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },+ "within_next_x_days": {+ "expected_type": "string",+ "format": {+ "type": "number"+ }+ },"is_empty": {"expected_type": "boolean","format": {diff --git a/client/lib/forms/FormLogicConditionChecker.js b/client/lib/forms/FormLogicConditionChecker.jsindex de329201f..b74fafe49 100644--- a/client/lib/forms/FormLogicConditionChecker.js+++ b/client/lib/forms/FormLogicConditionChecker.js@@ -238,6 +238,60 @@ function checkNextYear(condition, fieldValue) {)}+function checkAtLeastXDaysAgo(condition, fieldValue) {+ if (!fieldValue || !condition.value) return false+ const fieldDate = new Date(fieldValue)+ if (Number.isNaN(fieldDate.getTime())) return false+ const today = new Date()+ const daysBefore = parseInt(condition.value, 10)+ if (isNaN(daysBefore) || daysBefore < 0) return false+ // Create target date by setting the date properly to avoid timezone issues+ const targetDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - daysBefore)+ // Return true if fieldDate is on or before the target date (X days before today)+ return fieldDate <= targetDate+}++function checkAtLeastXDaysFromNow(condition, fieldValue) {+ if (!fieldValue || !condition.value) return false+ const fieldDate = new Date(fieldValue)+ if (Number.isNaN(fieldDate.getTime())) return false+ const today = new Date()+ const daysAfter = parseInt(condition.value, 10)+ if (isNaN(daysAfter) || daysAfter < 0) return false+ // Create target date by setting the date properly to avoid timezone issues+ const targetDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + daysAfter)+ // Return true if fieldDate is on or after the target date (X days after today)+ return fieldDate >= targetDate+}++function checkWithinPastXDays(condition, fieldValue) {+ if (!fieldValue || !condition.value) return false+ const fieldDate = new Date(fieldValue)+ if (Number.isNaN(fieldDate.getTime())) return false+ const today = new Date()+ const daysBefore = parseInt(condition.value, 10)+ if (isNaN(daysBefore) || daysBefore < 0) return false+ // Create target date by setting the date properly to avoid timezone issues+ const targetDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - daysBefore)+ const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate())+ // Return true if fieldDate is between target date (X days ago) and today (inclusive)+ return fieldDate >= targetDate && fieldDate <= todayDate+}++function checkWithinNextXDays(condition, fieldValue) {+ if (!fieldValue || !condition.value) return false+ const fieldDate = new Date(fieldValue)+ if (Number.isNaN(fieldDate.getTime())) return false+ const today = new Date()+ const daysAfter = parseInt(condition.value, 10)+ if (isNaN(daysAfter) || daysAfter < 0) return false+ // Create target date by setting the date properly to avoid timezone issues+ const targetDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + daysAfter)+ const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate())+ // Return true if fieldDate is between today and target date (X days from now) (inclusive)+ return fieldDate >= todayDate && fieldDate <= targetDate+}+function checkLength(condition, fieldValue, operator = "===") {if (!fieldValue || fieldValue.length === 0) return falseswitch (operator) {@@ -380,6 +434,14 @@ function dateConditionMet(propertyCondition, value) {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':+ return checkAtLeastXDaysFromNow(propertyCondition, value)+ case 'within_past_x_days':+ return checkWithinPastXDays(propertyCondition, value)+ case 'within_next_x_days':+ return checkWithinNextXDays(propertyCondition, value)case "is_empty":return checkIsEmpty(propertyCondition, value)case "past_week":