Skip to content

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

Open
SAY-5 wants to merge 2 commits into
airframesio: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 2 commits into
airframesio: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

    • Fixed UTC date/time parsing and formatting, correcting month indexing, ensuring proper year fallback, and stabilizing seconds handling.
  • Tests

    • Added deterministic tests for date/time utilities, covering month-end rollover and time-string formats (including seconds).

@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: ec99d2ea-58bb-4fec-abe9-89560c5bc7da

📥 Commits

Reviewing files that changed from the base of the PR and between 1dc9384 and 11211f7.

📒 Files selected for processing (1)
  • lib/DateTimeUtils.test.ts
✅ Files skipped from review due to trivial changes (1)
  • lib/DateTimeUtils.test.ts

Walkthrough

Fixes an off-by-one month bug in UTCDateTimeToString by building the UTC Date via Date.UTC(...) with month adjusted from ACARS 1–12 to JS 0–11; adds deterministic Jest tests including a month-end rollover regression and seconds-aware time parsing.

Changes

UTC date parsing and tests

Layer / File(s) Summary
Data Shape / Parsing
lib/DateTimeUtils.ts
Replaces incremental setUTC* mutations with a single Date.UTC(year, month-1, day, hour, minute, second) construction; subtracts 1 from parsed month; when dateString.length !== 6 uses current UTC year; only parses seconds when timeString.length === 6.
Entry / API
lib/DateTimeUtils.ts (same file, different ranges)
UTCDateTimeToString(dateString, timeString) now derives all UTC components from inputs and returns the formatted UTC string from the constructed Date.
Deterministic Regression Test
lib/DateTimeUtils.test.ts
New Jest suite verifying: correct DDMMYY decoding (month/day/year), month-end rollover fixed by pinning system time to 2026-03-31 ensuring 280226 yields Feb 28 2026, and time parsing accepts HHMMSS (verifies 12:30:45).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • kevinelliott

Poem

🐰 I nibbled bugs by moonlit light,
Subtracted one to make months right,
One Date.UTC call, tidy and neat,
Tests pinned steady, no more sleight—
February hops back in place tonight.

🚥 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 accurately describes the main fix: subtracting 1 from ACARS month before setUTCMonth to correct the off-by-one bug.
Linked Issues check ✅ Passed The PR fully addresses issue #424 by correcting month handling (subtract 1) and rebuilding with Date.UTC() for safer date construction, resolving the off-by-one bug described.
Out of Scope Changes check ✅ Passed All changes directly address the linked issue: month correction in DateTimeUtils.ts, robust date construction via Date.UTC, and comprehensive regression tests in DateTimeUtils.test.ts.
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

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