Skip to content

fix(datetime): subtract 1 from ACARS month before setUTCMonth (#424)#434

Open
SAY-5 wants to merge 1 commit intoairframesio:masterfrom
SAY-5:fix/issue-424-utc-month-off-by-one
Open

fix(datetime): subtract 1 from ACARS month before setUTCMonth (#424)#434
SAY-5 wants to merge 1 commit intoairframesio:masterfrom
SAY-5:fix/issue-424-utc-month-off-by-one

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 30, 2026

Summary

Fixes #424. UTCDateTimeToString passed the raw ACARS month digit (1-12) to Date.prototype.setUTCMonth, which expects 0-11. Every decoded date came out one month forward — 150226 (15 Feb 2026) decoded to 15 March 2026.

While addressing the off-by-one I also folded the construction into a single new Date(Date.UTC(...)) call. The original incremental setUTC* sequence is fragile when the system clock falls on a day that doesn't exist in the target month: setting day=28 on a Date already at the 31st silently rolls forward, so encoding 280226 while the host clock said 31 March would have decoded to 28 March.

Test plan

  • npx jest — full suite: 410 passed, 9 skipped, 89 suites
  • New DateTimeUtils.test.ts:
    • decodes a DDMMYY date with the ACARS 1-12 month convention — direct regression for Bug: DateTimeUtils.UTCDateTimeToString month is off-by-one #424
    • does not roll the month forward when the system date is later than the target month-end — uses jest.setSystemTime to pin a 31-day-month system clock and verifies the order-fragility fix
    • handles a six-digit time with seconds — exercises the HHMMSS branch

Summary by CodeRabbit

  • Bug Fixes

    • Resolved UTC date/time parsing and formatting issues, including improved month handling and year fallback behavior
    • Enhanced seconds value processing in time string formatting
  • Tests

    • Added comprehensive test coverage for date/time utilities, validating correct formatting and edge case handling

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 65046be0-441a-4ab3-b340-eec1b2b186c0

📥 Commits

Reviewing files that changed from the base of the PR and between 48f4cce and 1dc9384.

📒 Files selected for processing (2)
  • lib/DateTimeUtils.test.ts
  • lib/DateTimeUtils.ts

Walkthrough

Fixes a month off-by-one bug in UTCDateTimeToString where ACARS 1-12 month numbering was not converted to JavaScript's 0-11 indexing. Refactors the function to construct dates via Date.UTC() in a single call and adds comprehensive test coverage including a deterministic regression test for month-end edge cases.

Changes

Cohort / File(s) Summary
Test Suite
lib/DateTimeUtils.test.ts
New Jest test file with 31 lines covering correct month/day/year parsing, a deterministic month-end rollover regression test pinned to 31 March 2026, and validation of time string (HHMMSS) formatting.
Implementation & Bug Fix
lib/DateTimeUtils.ts
Refactored UTCDateTimeToString to use single Date.UTC() constructor call instead of multiple setUTC* mutations; corrects month handling by subtracting 1 from parsed value (ACARS 1–12 to JS 0–11); updates year fallback logic for non-6-character date strings; explicitly handles seconds parsing for 6-character time strings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • kevinelliott

Poem

🐰 A month was lost, off by one it flew,
JavaScript and ACARS couldn't quite align true,
Now UTC constructs the date complete,
One call instead of stumbling feet—
February stays February, bugs retreat! 🌙✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main bug fix: subtracting 1 from ACARS month before setUTCMonth. It matches the primary change in the PR.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #424 by fixing the off-by-one month bug and reworking date construction to use Date.UTC for robustness, with regression tests added.
Out of Scope Changes check ✅ Passed All changes in DateTimeUtils.ts and the new DateTimeUtils.test.ts file are directly scoped to fixing the month off-by-one bug and adding related tests; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ 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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

Comment thread lib/DateTimeUtils.test.ts
// (28 Feb 2026) used to roll forward to March because the order of
// setUTC* calls applied "set day=28" to a Date already at the 31st.
jest.useFakeTimers();
jest.setSystemTime(new Date(Date.UTC(2026, 2, 31, 0, 0, 0)));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't understand why we're setting system time. Can you explain?

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.

Bug: DateTimeUtils.UTCDateTimeToString month is off-by-one

2 participants