Skip to content

feat: date and time validation#2689

Open
sanny-io wants to merge 9 commits into
zenstackhq:devfrom
sanny-io:feat/date-strings
Open

feat: date and time validation#2689
sanny-io wants to merge 9 commits into
zenstackhq:devfrom
sanny-io:feat/date-strings

Conversation

@sanny-io
Copy link
Copy Markdown
Contributor

@sanny-io sanny-io commented May 31, 2026

Closes #1725

Summary by CodeRabbit

  • New Features

    • Added @date validation attribute for string fields to validate ISO date format with optional custom error messages.
    • Added isDate() and isTime() validation helper for use in custom validation rules.
    • Added @time support for ISO time validation.
  • Tests

    • Updated and added unit and end-to-end tests, fixtures, and schema samples to cover date/time validation, parsing, and type-inference adjustments.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0fae9b20-f41e-4aa7-8c25-90e29c914417

📥 Commits

Reviewing files that changed from the base of the PR and between 9dc1d1b and 10125d0.

📒 Files selected for processing (8)
  • packages/cli/test/db/pull.test.ts
  • packages/language/res/stdlib.zmodel
  • packages/zod/src/utils.ts
  • packages/zod/test/factory.test.ts
  • packages/zod/test/schema/schema.ts
  • packages/zod/test/schema/schema.zmodel
  • tests/e2e/orm/validation/custom-validation.test.ts
  • tests/e2e/orm/validation/toplevel.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/zod/test/schema/schema.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/e2e/orm/validation/toplevel.test.ts
  • packages/zod/test/schema/schema.zmodel
  • packages/language/res/stdlib.zmodel
  • tests/e2e/orm/validation/custom-validation.test.ts
  • packages/zod/test/factory.test.ts
  • packages/zod/src/utils.ts

📝 Walkthrough

Walkthrough

Adds ISO date support: a @date attribute and isDate() rule in the language stdlib, Zod integration mapping @date/isDate to Zod date validators, updates generated test schema, factory/type tests, e2e validation tests, and a CLI db-pull test fixture.

Changes

ISO Date Validation Support

Layer / File(s) Summary
Language attribute and function contracts
packages/language/res/stdlib.zmodel
New @date validation attribute with optional message for StringField, and isDate() validation rule function for ISO date checking.
Zod validator implementation
packages/zod/src/utils.ts
Zod integration: @date handled in addStringValidation mapping to .date(); stringFuncZodMap extended with isDate: 'date'; evalCall dispatches isDate via the shared map.
Test schema updates
packages/zod/test/schema/schema.zmodel, packages/zod/test/schema/schema.ts
User model updated: birthdate retyped to String? @Date, `localTime: String? `@time added, and createdAt: DateTime? added.
Factory and schema type validation tests
packages/zod/test/factory.test.ts
Fixtures and type/parsing tests adjusted for createdAt DateTime; added @date validation tests for birthdate (invalid/valid/null) and @time tests for localTime; optionality/type assertions updated.
End-to-end validation tests
tests/e2e/orm/validation/custom-validation.test.ts, tests/e2e/orm/validation/toplevel.test.ts
E2E coverage added for isDate() custom rule and toplevel @date attribute; tests assert rejection of invalid ISO strings and acceptance of valid ISO dates.
CLI db-pull test fixture
packages/cli/test/db/pull.test.ts
Updated inline test schema to include birthdate String @date`` to ensure db pull preserves field-level validation attributes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • zenstackhq/zenstack#2672: Adds a similar string-validation attribute and evaluator mapping (e.g., phone validation) and touches the same validation-dispatch logic.

Suggested reviewers

  • ymc9

Poem

🐰 I nibbled at strings and found a date,
I taught the parser to check its fate,
From stdlib rules to Zod's careful parse,
Tests and schemas now sing in terse verse,
Hop, hop — the calendar's in place!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: date and time validation' accurately reflects the main objective of adding ISO date and time validation support across the codebase, including new @date and @time attributes, validation rules, and comprehensive test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/cli/test/db/pull.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/zod/src/utils.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/zod/test/factory.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sanny-io sanny-io changed the title feat: date strings feat: date validation May 31, 2026
@sanny-io sanny-io marked this pull request as ready for review May 31, 2026 05:34
@sanny-io sanny-io changed the title feat: date validation feat: date and time validation May 31, 2026
@sanny-io
Copy link
Copy Markdown
Contributor Author

This was originally just date validation, but these are so closely related I felt it would be better in the same PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add support for Zod date and time string validator in addition to datetime

1 participant