Skip to content

feat: date and time validation#2689

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

feat: date and time validation#2689
sanny-io wants to merge 11 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 for string fields (ISO date strings) and corresponding isDate() rule; improved isTime() rule support.
  • Tests
    • Expanded unit and end-to-end tests and fixtures to cover date/time validation, parsing, and adjusted type-inference expectations.

@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: bf619930-a229-4c6a-a700-068d456a4f54

📥 Commits

Reviewing files that changed from the base of the PR and between 10125d0 and 401c550.

📒 Files selected for processing (2)
  • packages/language/res/stdlib.zmodel
  • packages/zod/src/utils.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/zod/src/utils.ts
  • packages/language/res/stdlib.zmodel

📝 Walkthrough

Walkthrough

Adds ISO date support: a @date attribute and isDate() rule in the language stdlib, Zod integration mapping @date/isDate to Zod date/time validators, updated generated schema, factory/type tests, e2e validation tests, and a CLI db-pull 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/isTime; evaluator evalCall dispatches these predicates and uses z.iso.time for time checks.
Generated 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 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.
  • zenstackhq/zenstack#2684: Related changes extending Zod/string validation pipeline and stdlib validation attributes.

Suggested reviewers

  • ymc9

Poem

🐰 I nibbled at strings till dates came true,
I taught the parser the year-month-day cue,
From stdlib glyphs to Zod's careful parse,
Tests now hop in line and pass with sparse,
Hop—the calendar’s snug and new!

🚥 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 title 'feat: date and time validation' directly and clearly summarizes the main changes: adding support for date and time validation attributes and corresponding validators to the codebase.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #1725: adds @date attribute and isDate() validator for YYYY-MM-DD format strings, and @time attribute and isTime() validator for HH:MM:SS format with precision support.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing date and time validation: stdlib declarations, Zod integration, test updates, and test schema modifications. No unrelated changes detected.

✏️ 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/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.


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.

@sanny-io sanny-io marked this pull request as draft June 1, 2026 04:14
@sanny-io sanny-io marked this pull request as ready for review June 1, 2026 07:12
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