Skip to content

date fields of GS1 barcodes should consider the timezone offset - #2

Closed
yoolandes wants to merge 1 commit into
MaximBelov:masterfrom
yoolandes:bugfixes/fix_values_of_date_fields
Closed

yoolandes wants to merge 1 commit into
MaximBelov:masterfrom
yoolandes:bugfixes/fix_values_of_date_fields

Conversation

@yoolandes

Copy link
Copy Markdown

At the moment the method parseBarcode instantiates a date with the users current timezone. This could be problematic when storing the values of the date fields in a database.

For example the library parses the following GS1 barcode: 15240300
A user who lives in a timezone with a negative offset of minus 1 hour would send the following ISO date to the server: `2024-03-30T23:00:00.000Z
The server interprets the date as an UTC date and would store the wrong value "2024-03-30" in the database.

Reading the date fields as UTC dates would fix this problem.

@seanlynch7194 seanlynch7194 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.

I ran the updated code through the scenario that previously triggered the bug and can confirm the patch resolves it. No unexpected behaviour observed.

@MaximBelov

Copy link
Copy Markdown
Owner

Thanks for this — the problem is real, and #15 fixes it a different way.

Your reading of it is right: a date parsed here, serialised with toISOString(), can land on the wrong day. What made me hesitate is that moving data to UTC does not remove the ambiguity, it moves who gets caught by it. After the change a caller reading the same date with getDate() sees the previous day west of Greenwich. Merged onto current master that shows up in the suite: 1 spec fails in CET and 3 in New York — specs added since you opened this, which assert the local day.

master has also grown a second date parser since, for the four digit year of 7250/7251. With only parseDate moved to UTC the two would disagree about what midnight means.

So #15 leaves data alone and adds isoDate next to it:

parseBarcode("]C117250630").parsedCodeItems[0].isoDate   // "2025-06-30", in any timezone

That is the value to send to a server. Nothing existing changes, and there is no timezone in which someone is worse off.

Closing this one, but the report is what got it fixed — thank you.

@MaximBelov MaximBelov closed this Aug 13, 2026
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