Skip to content

Support GS1-128 date AIs with a four-digit year (7250, 7251)#498

Open
gaoflow wants to merge 1 commit into
arthurdejong:masterfrom
gaoflow:gs1-128-four-digit-year-dates
Open

Support GS1-128 date AIs with a four-digit year (7250, 7251)#498
gaoflow wants to merge 1 commit into
arthurdejong:masterfrom
gaoflow:gs1-128-four-digit-year-dates

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 16, 2026

Copy link
Copy Markdown

GS1 Application Identifiers 7250 (DOB) and 7251 (DOB TIME) carry a four-digit
year (N8 = YYYYMMDD, N12 = YYYYMMDDhhmm), but gs1_128 only handled
two-digit-year date formats, so both AIs were broken in either direction:

  • info('725019800715') raised a bare ValueError: time data '19800715' does not match format '%y%m%d%H'. The N8 value fell through to the generic
    '%y%m%d%H%M%S'[:len(value)] branch, which parsed the four-digit year as YY.
  • info('7251198007151430') raised ValueError because the 12-digit N12
    value was treated as two YYMMDD dates and '198007' is not a valid date.
  • encode({'7250': datetime.date(1980, 7, 15)}) raised
    ValueError: unsupported format: N8.

_encode_date() now formats N8 as %Y%m%d and N12 as %Y%m%d%H%M, and
_decode_date() parses them back with the matching four-digit-year formats.
N12 is also removed from the two-date branch: the only date AI that encodes a
pair of YYMMDD dates is 7007 (N6[+N6]), whereas 7251 is a single datetime.

Round-trip doctests for both AIs are added to tests/test_gs1_128.doctest.

AI 7250 (DOB, N8 YYYYMMDD) and 7251 (DOB TIME, N12 YYYYMMDDhhmm) use a
four-digit year, but _encode_date() and _decode_date() only handled
two-digit-year formats. Encoding raised "unsupported format: N8" and
decoding raised a bare ValueError: N8 was parsed with '%y%m%d%H' and N12
was mistaken for two YYMMDD dates.

Handle N8 and N12 explicitly in both directions and stop treating N12 as
a pair of dates (only N6[+N6] / N6..12 encode two dates).
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