这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@SethFalco
Copy link
Member

@SethFalco SethFalco commented Oct 19, 2025

If the JSON Resume only specifies a year in a date field, then we'll assume we should only display a year.

For example:

  • 2022-01 → Jan 2022
  • 2022 → 2022

Related

Summary by CodeRabbit

  • Refactor
    • Date formatting now dynamically adapts based on input type (full date vs. year-only), improving display consistency.
    • Code quality enhanced with improved type annotations on internal date and utility helper functions.

@coderabbitai
Copy link

coderabbitai bot commented Oct 19, 2025

Walkthrough

Refactored date formatting logic in index.js by extracting locale and format constants, updating the date helper with conditional format selection based on input type (full date vs. year-only), and adding JSDoc parameter type annotations to helper functions, while preserving the public API.

Changes

Cohort / File(s) Summary
Date Formatting & JSDoc Refactor
index.js
Introduced top-level constants: DATE_LOCALE, LONG_DATE_FORMAT, and SHORT_DATE_FORMAT. Updated date helper to conditionally select format based on hyphen presence in input (full date vs. year-only). Added explicit JSDoc parameter type annotations for body parameters in date, markdown, and link helpers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Constants hop and dance in rows,

Dates now pick their format flows,

Hyphen-hints guide the way,

JSDoc blooms, brightening the day! 📅✨

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 PR title "fix: omit month if date specified is only year" directly aligns with the main change in the changeset. The modifications to index.js implement exactly this behavior by introducing conditional date formatting that uses SHORT_DATE_FORMAT (year only) when the input contains no hyphen and LONG_DATE_FORMAT (month and year) when it does. The title accurately summarizes the primary improvement: adjusting date display logic to show only the year when a date field contains only a year value, which matches the stated PR objectives and examples provided.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@SethFalco SethFalco merged commit a6456a9 into jsonresume:main Oct 19, 2025
2 of 3 checks passed
Copy link

@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

🧹 Nitpick comments (2)
index.js (2)

65-67: Consider adding validation for more robust year-only detection.

The split('-').length !== 1 check works well for properly formatted ISO dates, but could be more explicit. For example, a malformed input like "2022-" would be treated as a full date but might produce unexpected results.

For increased clarity and robustness, consider an explicit regex check:

-  const localeString = body.split('-').length !== 1
-    ? date.toLocaleDateString(DATE_LOCALE, LONG_DATE_FORMAT)
-    : date.toLocaleDateString(DATE_LOCALE, SHORT_DATE_FORMAT);
+  const isYearOnly = /^\d{4}$/.test(body);
+  const localeString = isYearOnly
+    ? date.toLocaleDateString(DATE_LOCALE, SHORT_DATE_FORMAT)
+    : date.toLocaleDateString(DATE_LOCALE, LONG_DATE_FORMAT);

63-64: Add error handling for invalid dates in the date helper.

The Handlebars date helper at lines 58-67 lacks validation for date input. While the falsy check at line 59 handles missing dates, it doesn't catch invalid date strings (e.g., "invalid" or "2024-13-45"). Calling toISOString() on an Invalid Date object throws a RangeError. Add a validation check before line 64, such as:

if (Number.isNaN(date.getTime())) {
  return body; // or handle error appropriately
}

This provides defensive error handling against malformed date input that bypasses the schema.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39c7efd and 913186b.

📒 Files selected for processing (1)
  • index.js (2 hunks)
🔇 Additional comments (2)
index.js (2)

6-10: LGTM! Good extraction of date formatting constants.

The constants improve maintainability and make the date formatting behavior explicit. The JSDoc type annotations for Intl.DateTimeFormatOptions are appropriate.


58-58: LGTM! Good addition of parameter type annotations.

The JSDoc @param {string} annotations improve developer experience and code documentation across all three Handlebars helpers.

Also applies to: 72-72, 76-76

@SethFalco SethFalco deleted the year-only branch October 19, 2025 18:57
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.

Only show year in date fields if only year was specified

1 participant