Skip to content

Carry the date of a date element as text - #15

Merged
MaximBelov merged 1 commit into
masterfrom
feat/iso-date-string
Aug 13, 2026
Merged

MaximBelov merged 1 commit into
masterfrom
feat/iso-date-string

Conversation

@MaximBelov

Copy link
Copy Markdown
Owner

Closes the problem behind #2 without the trade-off that PR carries.

A date with no time of day cannot be carried unambiguously in a Date. Reading one back means choosing local getters or UTC ones, and either choice shifts the day for someone:

process.env.TZ = "Pacific/Auckland";
parseBarcode("]C117250630").parsedCodeItems[0].data.toISOString();  // 2025-06-29 — wrong day

So date elements now also carry isoDate:

parseBarcode("]C117250630").parsedCodeItems[0].isoDate            // "2025-06-30"
parseBarcode("]C17251198506301435").parsedCodeItems[0].isoDate     // "1985-06-30T14:35"

It is the resolved date, so a day of 00 reads as the last day of that month. Empty on elements that hold no date.

Nothing existing changes. #2 instead moves data itself to UTC, which fixes the ISO case and breaks the local-getter one — merged onto current master it fails 1 spec in CEST and 3 in New York, and leaves parseDate and parseLongDate disagreeing about midnight.

371 specs, 0 failures, run in UTC, Dublin and New York. Coverage still 100%.

A date without a time of day cannot be carried unambiguously in a Javascript
Date. Reading one back means choosing between the local getters and the UTC
ones, and either choice shifts the day for somebody: parseBarcode("]C117250630")
serialised with toISOString() from Auckland gives the 29th of June.

Date elements now also carry isoDate, read off the getters the date was built
with, so it says the day the barcode says wherever the reader sits. Elements
holding a time put that there too, as "1985-06-30T14:35".

The date is the resolved one rather than the digits as scanned, so a day of
"00" reads as the last day of that month, matching data. Every other kind of
element has isoDate empty.

Nothing existing changes, which is the point: the alternative was moving data
itself to UTC, and that trades one set of callers for another.
@MaximBelov
MaximBelov merged commit 97c02c2 into master Aug 13, 2026
1 check passed
@MaximBelov
MaximBelov deleted the feat/iso-date-string branch August 13, 2026 10:16
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