Skip to content

fix(parser): correct WhatsApp TXT date order when the preferred month is invalid - #506

Merged
hellodigua merged 1 commit into
ChatLab:mainfrom
Omair-Asdaq:fix/whatsapp-txt-date-order
Nov 4, 2026
Merged

hellodigua merged 1 commit into
ChatLab:mainfrom
Omair-Asdaq:fix/whatsapp-txt-date-order

Conversation

@Omair-Asdaq

Copy link
Copy Markdown
Contributor

Problem

The WhatsApp browser-safe text parser misreads dates whose day is above 12 when the export is month-first, and dates whose day is above 12 when the file is day-first with a short year. For example:

  • 12/25/2024 was read as day 12, month 25 - an invalid month
  • 13/01/24 was read as month 13, day 01 - an invalid month

Both are valid WhatsApp timestamps and come out of the parser as Invalid Date.

Change

buildTimestamp now treats the second part as a month only when it can actually be one. In the long-year branch a second part above 12 switches to month-first; in the short-year branch a first part above 12 switches to day-first. Anything ambiguous (both parts 12 or below) keeps the order the file's locale already implied, so the existing behaviour is unchanged for those.

Tests

New case in packages/parser/src/browser/whatsapp.test.ts covering 12/25/2024, 13/01/24, 25/12/24, 02/01/2024, 01/02/24 and a year-first date.

  • without the change: 1 failed - the new case, with the timestamps coming back as invalid
  • with the change: 4 passed
  • whole parser package: 69 passed

Known limitations

Ambiguous dates where both leading parts are 12 or below still follow the locale's preferred order; this change only corrects the case where the preferred order is impossible.

… is invalid

TXT exports encode dates as month/day/year or day/month/year depending on the
device locale, and the parser infers the order from the digits alone. When the
preferred order produced a month outside 1-12 the value was still passed to
Date(), which rolls it into another month or year instead of failing.

That turned ordinary export lines into wrong timestamps:
  12/25/2024 -> 2026-01-12 (should be 2024-12-25)
  13/01/24   -> 2025-01-01 (should be 2024-01-13)
  25/12/24   -> 2026-01-12 (should be 2024-12-25)

A component above 12 cannot be a month, so switch to the other order only when
the preferred reading is impossible. Dates that already resolved correctly keep
their existing interpretation, including the ambiguous month-first cases
(01/02/24) and year-first exports (2024/01/02).
@Omair-Asdaq
Omair-Asdaq marked this pull request as ready for review November 3, 2026 17:27
Copilot AI balanced review requested due to automatic review settings November 3, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T17:30:47.165775Z 50c9b3e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@hellodigua
hellodigua merged commit c258a13 into ChatLab:main Nov 4, 2026
1 check passed
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.

3 participants