Skip to content

Commit d2dcf9a

Browse files
chtituxclaude
andcommitted
Fix end-of-validity computation: don't add validityDuration to explicit end-of-validity fields
validityDuration is the duration of the dynamic ticket (level2), not an offset to add to endOfValidityYear/Day/Time. Only use validityDuration in the v1 fallback path (issuingTime + duration). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9543f9b commit d2dcf9a

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/time-helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export function getIssuingTime(ticket: UicBarcodeTicket): Date | undefined {
4949
* Compute the end-of-validity timestamp as a UTC Date.
5050
*
5151
* - **v2 headers**: `endOfValidityYear` + `endOfValidityDay` +
52-
* `endOfValidityTime` (minutes) + `validityDuration` (seconds).
52+
* `endOfValidityTime` (minutes). `validityDuration` is ignored
53+
* when explicit end-of-validity fields are present.
5354
* - **v1 headers**: issuing time + `validityDuration` (seconds).
5455
*
5556
* Returns `undefined` when required fields are missing.
@@ -59,8 +60,7 @@ export function getEndOfValidityTime(ticket: UicBarcodeTicket): Date | undefined
5960

6061
if (headerVersion(ticket) >= 2 && l1.endOfValidityYear != null && l1.endOfValidityDay != null) {
6162
return new Date(
62-
Date.UTC(l1.endOfValidityYear, 0, l1.endOfValidityDay, 0, l1.endOfValidityTime ?? 0)
63-
+ (l1.validityDuration ?? 0) * 1000,
63+
Date.UTC(l1.endOfValidityYear, 0, l1.endOfValidityDay, 0, l1.endOfValidityTime ?? 0),
6464
);
6565
}
6666

tests/time-helpers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ describe('getEndOfValidityTime', () => {
139139
const decoded = decodeTicket(bytesToHex(encoded));
140140
const time = getEndOfValidityTime(decoded);
141141
expect(time).toBeDefined();
142-
// Day 200 of 2025 = July 19, 12:00 + 3600s = 13:00
143-
expect(time!.toISOString()).toBe('2025-07-19T13:00:00.000Z');
142+
// Day 200 of 2025 = July 19, 12:00 — validityDuration is NOT added
143+
expect(time!.toISOString()).toBe('2025-07-19T12:00:00.000Z');
144144
});
145145

146146
it('computes v2 end-of-validity from issuing time + validityDuration only', () => {

0 commit comments

Comments
 (0)