Skip to content

fix: consolidate duplicated date formatting into src/utils/date.js - #698

Open
bhuvan-somisetty wants to merge 2 commits into
Project-HAMi:masterfrom
bhuvan-somisetty:fix/consolidate-date-formatting
Open

fix: consolidate duplicated date formatting into src/utils/date.js#698
bhuvan-somisetty wants to merge 2 commits into
Project-HAMi:masterfrom
bhuvan-somisetty:fix/consolidate-date-formatting

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Date/time formatting was implemented independently in five places instead of going through the shared src/utils/date.js utility that already exists for it. src/utils/date.js's own formatDate/formatDateRange exports were unused dead code, while EventLanding.js, case-studies.js, and BlogPostItem/Header/index.js each carried their own copy with slightly different locale mapping and format options.

This wasn't just cosmetic duplication — it already caused a shipped bug (#659, dates showing a day early west of UTC). The fix for that bug had to be hand-applied to three separate files (commit a6b7c643) because there was no single place to patch, and EventLanding.js's independent copy wasn't touched by that fix at all (it happened to already have timeZone: "UTC" by luck).

This PR:

  • Extends src/utils/date.js with formatShortDate/formatNumericDate presets, and gives formatDateRange the formatRange feature-detection fallback that only EventLanding.js previously had (so it no longer throws in environments without Intl.DateTimeFormat.prototype.formatRange).
  • Replaces the local formatDate/formatDateRange copies in EventLanding.js, case-studies.js, and BlogPostItem/Header/index.js with imports from the shared utility, preserving each page's existing format granularity (long/short/numeric month) as an explicit named preset instead of an accidental divergence.
  • Adds unit tests for src/utils/date.js using Node's built-in test runner (node:test), including a regression test for the Blog post and case study dates are one day early west of UTC #659 UTC date-boundary bug across both en and zh locales, and a test for the formatRange fallback path. No new dependency: src/utils/package.json scopes "type": "module" to that directory so the ESM source runs directly under node --test without affecting the rest of the (CommonJS) repo or the webpack build.
  • Adds npm run test (wired into check:all and CI) and documents in CONTRIBUTING.md that date/time formatting should go through src/utils/date.js.

src/theme/BlogArchivePage/index.js already uses Docusaurus's useDateTimeFormat hook correctly and is left as-is — it's a different mechanism, not a duplicate of src/utils/date.js.

Verified in the built HTML for all three presets: case studies (short, en) Jul 2, 2026, case studies (short, zh) 2026年7月2日, blog post header (numeric, en) 3/19/2026, event landing page (long range, en) July 28 – 30, 2026.

Which issue(s) this PR fixes:

Fixes #697

Checklist:

  • npm run lint and npm run format:check pass
  • npm run build succeeds for both en and zh
  • Chinese translation updated if English docs changed (or noted why not) - N/A, no doc content changed
  • Commits are signed off (git commit -s)

Summary by CodeRabbit

  • Improvements

    • Standardized date displays across event pages, case studies, and blog posts.
    • Improved date formatting for English and Chinese locales.
    • Added reliable date-range display for browsers that lack native range-formatting support.
  • Documentation

    • Updated contributor guidance and CI checklist to include unit tests.
  • Testing

    • Expanded automated coverage for date formatting and compatibility scenarios.

@hami-robot

hami-robot Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bhuvan-somisetty
Once this PR has been reviewed and has the lgtm label, please assign wawa0210 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot
hami-robot Bot requested review from archlitchi and rootsongjc August 2, 2026 03:19
@netlify

netlify Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploy Preview for project-hami ready!

Name Link
🔨 Latest commit cd7cdf9
🔍 Latest deploy log https://app.netlify.com/projects/project-hami/deploys/6a709e9703f7bc0008a832f3
😎 Deploy Preview https://deploy-preview-698--project-hami.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Date/time formatting was reimplemented independently in EventLanding.js,
case-studies.js, and BlogPostItem/Header/index.js instead of using the
shared src/utils/date.js utility, which itself had unused exports. This
already caused a shipped bug (Project-HAMi#659) that had to be hand-patched across
three separate files because there was no single source of truth.

- Extend src/utils/date.js with formatShortDate/formatNumericDate presets
  and give formatDateRange the formatRange feature-detection fallback
  that only EventLanding.js previously had.
- Replace the local formatDate/formatDateRange copies in EventLanding.js,
  case-studies.js, and BlogPostItem/Header/index.js with imports from the
  shared utility, preserving each page's existing format granularity as
  an explicit named preset.
- Add unit tests for src/utils/date.js using Node's built-in test runner,
  including a regression test for the Project-HAMi#659 UTC date-boundary bug.
- Wire npm run test into check:all and CI, and document the
  "date formatting goes through src/utils/date.js" convention in
  CONTRIBUTING.md.

Fixes Project-HAMi#697

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

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 Plus

Run ID: ddd01750-fd7e-406d-a809-7e99efc45c2a

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec2dc3 and cd7cdf9.

📒 Files selected for processing (9)
  • .github/workflows/docs-health.yml
  • CONTRIBUTING.md
  • package.json
  • src/components/EventLanding.js
  • src/pages/case-studies.js
  • src/theme/BlogPostItem/Header/index.js
  • src/utils/date.js
  • src/utils/date.test.js
  • src/utils/package.json

📝 Walkthrough

Walkthrough

The change centralizes date formatting in shared UTC-based utilities, updates event, case-study, and blog rendering, adds utility tests, and expands Node test discovery across scripts, CI, and contributor documentation.

Changes

Date formatting and validation

Layer / File(s) Summary
Shared date utilities and regression tests
src/utils/date.js, src/utils/date.test.js, src/utils/package.json
Shared long, short, numeric, and range formatters use UTC. Range formatting includes a formatRange fallback. Tests cover locales and fallback behavior.
Date rendering integrations
src/components/EventLanding.js, src/pages/case-studies.js, src/theme/BlogPostItem/Header/index.js
Components use shared date utilities instead of local formatting implementations.
Test workflow and contributor checks
package.json, .github/workflows/docs-health.yml, CONTRIBUTING.md
The test script uses Node test discovery. Aggregate checks, CI, and contributor guidance now include unit tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: kind/bug

Suggested reviewers: rootsongjc, archlitchi

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 clearly describes consolidating duplicated date formatting into the shared utility.
Linked Issues check ✅ Passed The changes implement the shared date utility, replace duplicated logic, preserve format variants, add locale and fallback tests, and document the convention for issue #697.
Out of Scope Changes check ✅ Passed The CI, test script, module configuration, and documentation changes directly support the linked issue objectives.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/consolidate-date-formatting branch from 77a4489 to 2116467 Compare August 2, 2026 03:20
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

@rootsongjc @mesutoezdil could one of you take a look when you get a chance? All checks are green, just needs a review/lgtm. Thanks!

@fishman

fishman commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Looks like an oversight. I thought I replaced all Eventlanding occurances after creating the date.js helper. But it's nice to see it used for BlogPosts as well.

/lgtm

@hami-robot hami-robot Bot added the lgtm label Aug 2, 2026
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look! Yeah, EventLanding had its own copy with the UTC fix baked in already, so it just needed to be swapped over to the shared util like the rest. Glad it's cleaner now for BlogPosts too.

Resolve conflicts in .github/workflows/docs-health.yml and package.json
by consolidating the two independently-added test scripts (mine for
src/utils/date.test.js, upstream's for the markdown edge function
tests) into a single npm run test that node --test discovers via its
default globbing.
@hami-robot hami-robot Bot removed the lgtm label Aug 3, 2026
@hami-robot

hami-robot Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Conflicts resolved, merged in the latest master and everything's green now. @rootsongjc thanks again for merging my last one, appreciate the guidance - would love your eyes on this when you get a chance!

@coderabbitai coderabbitai Bot added the kind/bug Something isn't working label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Date formatting is reimplemented in 5+ places with drifting locale/format logic (root cause behind #659, only partially fixed)

2 participants