Support GS1-128 date AIs with a four-digit year (7250, 7251)#498
Open
gaoflow wants to merge 1 commit into
Open
Support GS1-128 date AIs with a four-digit year (7250, 7251)#498gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GS1 Application Identifiers 7250 (DOB) and 7251 (DOB TIME) carry a four-digit
year (
N8=YYYYMMDD,N12=YYYYMMDDhhmm), butgs1_128only handledtwo-digit-year date formats, so both AIs were broken in either direction:
info('725019800715')raised a bareValueError: time data '19800715' does not match format '%y%m%d%H'. TheN8value fell through to the generic'%y%m%d%H%M%S'[:len(value)]branch, which parsed the four-digit year asYY.info('7251198007151430')raisedValueErrorbecause the 12-digitN12value was treated as two
YYMMDDdates and'198007'is not a valid date.encode({'7250': datetime.date(1980, 7, 15)})raisedValueError: unsupported format: N8._encode_date()now formatsN8as%Y%m%dandN12as%Y%m%d%H%M, and_decode_date()parses them back with the matching four-digit-year formats.N12is also removed from the two-date branch: the only date AI that encodes apair of
YYMMDDdates is 7007 (N6[+N6]), whereas 7251 is a single datetime.Round-trip doctests for both AIs are added to
tests/test_gs1_128.doctest.