Skip to content

Conversation

@zoriya
Copy link
Contributor

@zoriya zoriya commented Jan 3, 2026

When t.Date() is containing a string, we still want to ensure the string is in iso format.
Since we are already parsing the date, we can just use the .toISOString() method of Date.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed date encoding behavior: string date inputs are now properly parsed, validated, and normalized to ISO format instead of being returned unchanged. This ensures consistent date formatting throughout the system. Invalid dates continue to be properly rejected with validation errors.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 3, 2026

Walkthrough

The Date.Encode method in ElysiaType has been modified to parse string inputs into Date objects, validate them, and return ISO string representations instead of passing through the original input strings.

Changes

Cohort / File(s) Summary
Date type encoding logic
src/type-system/index.ts
Modified ElysiaType.Date.Encode to parse string inputs into Date objects, validate against invalid dates, and return ISO string format instead of the original string input. Invalid dates still trigger ValidationError.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A date now hops through parsing grace,
String to Date at swifter pace,
ISO format, clean and bright—
No more strings pass through the night!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Always convert dates to iso string' directly and clearly summarizes the main change: modifying the Date.Encode behavior to convert date strings to ISO format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c163c89 and 27c17f0.

📒 Files selected for processing (1)
  • src/type-system/index.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/type-system/index.ts (1)
src/type-system/format.ts (1)
  • parseDateTimeEmptySpace (140-145)

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/type-system/index.ts (1)

246-260: Add schema constraint validation for consistency with Decode.

The Encode method successfully normalizes string inputs to ISO format, which aligns with the PR objective. However, there's a validation inconsistency: the Decode method (line 242) validates parsed dates against schema constraints using compiler.Check(date), but the Encode method doesn't perform this validation for either Date instances or parsed strings.

If the schema includes constraints like minimum or maximum dates, the Encode method could allow dates outside the valid range, creating an asymmetry with Decode.

🔎 Suggested fix to add compiler validation
 .Encode((value) => {
-    if (value instanceof Date) return value.toISOString()
+    if (value instanceof Date) {
+        if (!compiler.Check(value)) throw compiler.Error(value)
+        return value.toISOString()
+    }
     if (typeof value === 'string') {
         const parsed = new Date(parseDateTimeEmptySpace(value))
 
         if (isNaN(parsed.getTime()))
             throw new ValidationError('property', schema, value)
 
+        if (!compiler.Check(parsed)) throw compiler.Error(parsed)
         return parsed.toISOString()
     }
 
     if (!compiler.Check(value)) throw compiler.Error(value)
 
     return value
 })
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c163c89 and 27c17f0.

📒 Files selected for processing (1)
  • src/type-system/index.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/type-system/index.ts (1)
src/type-system/format.ts (1)
  • parseDateTimeEmptySpace (140-145)

@SaltyAom SaltyAom merged commit 920c18b into elysiajs:main Jan 4, 2026
1 of 2 checks passed
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.

2 participants