Skip to content

fix: correct UPS and USPS time parsing - #43

Merged
egg- merged 1 commit into
masterfrom
fix/ups-usps-time-parsing
Aug 5, 2026
Merged

fix: correct UPS and USPS time parsing#43
egg- merged 1 commit into
masterfrom
fix/ups-usps-time-parsing

Conversation

@egg-

@egg- egg- commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes two time-parsing bugs in the UPS and USPS couriers, both originally reported in #35.

Background

@aldin-alagic opened #35 in December 2022 with fixes for exactly these two bugs. It sat unreviewed, and by the time v3 landed the sources had moved from lib/ to src/, so the patch no longer applied. The bugs were still there — the v3 rewrite carried them over unchanged, and the comparison I ran against v2 could not catch them because both versions were wrong in the same way.

Changes

  • UPS — UPS reports a 12-hour clock as 10:53 P.M., but the format string read it as HH:mm. The meridiem was ignored, so every afternoon event was recorded twelve hours early. Seven of the twelve activities in the recorded fixture are P.M., so this was wrong more often than it was right. dayjs's A token only matches PM, not P.M., so the periods are stripped before parsing with h:mm A.
  • USPS — runs of whitespace inside the date cell are collapsed before parsing, and the format list now also accepts a space after the second comma. The page has shipped several layouts of this string over the years.
  • Added a regression test for each. The existing sweep only asserted that a timestamp parsed at all, which a twelve-hour error passes cleanly.

Key files

src/courier/ups.ts, src/courier/usps.ts, test/checkpoint-time.test.ts

Rollout / Follow-up

Folded into the unreleased 3.0.0 rather than a patch release, since v3 has not been published yet.

Closes #35.

Risks

UPS timestamps that consumers stored from earlier versions will not match what this returns for the same shipment — the old values were simply wrong for afternoon events.

Verification

Reverting either fix makes the new tests fail, which is how the UPS bug was confirmed rather than assumed.

UPS reports a 12-hour clock as "10:53 P.M.", but the format string read it
as `HH:mm`, so the meridiem was ignored and every afternoon event landed
twelve hours early. Seven of the twelve activities in the recorded fixture
are P.M., so this was wrong far more often than not.

dayjs only matches "PM", not "P.M.", so the periods have to be stripped
before parsing with `h:mm A`.

USPS gets the same treatment for whitespace: runs of spaces inside the date
cell are collapsed before parsing, and the format list now also accepts a
space after the second comma.

Both were reported in #35 by @aldin-alagic in 2022. That PR targeted the old
`lib/` tree and could no longer be merged after the v3 rewrite, so the fixes
are reapplied here with a regression test for each — the existing sweep only
checked that a timestamp parsed, not that it landed on the right hour.
@egg- egg- mentioned this pull request Aug 5, 2026
@egg-
egg- merged commit 86a0fd2 into master Aug 5, 2026
3 checks passed
@egg-
egg- deleted the fix/ups-usps-time-parsing branch August 5, 2026 01:42
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.

1 participant