From 4764761c898dd65bcdf2af21d2cc582fad7ee01d Mon Sep 17 00:00:00 2001 From: Jens Spanier Date: Tue, 8 Aug 2023 13:18:18 +0200 Subject: [PATCH 1/4] Use `toISOString` instead of manual build --- src/utils.ts | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 2ce999f..578c483 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -36,30 +36,7 @@ function dateToW3CString(date: Date) { return undefined; } - const paddedMonth = padMeTwo(date.getMonth() + 1); - const paddedDay = padMeTwo(date.getDate()); - const paddedHour = padMeTwo(date.getHours()); - const paddedMinutes = padMeTwo(date.getMinutes()); - const paddedSeconds = padMeTwo(date.getSeconds()); - - /** - * Date.prototype.getTimezoneOffset returns the timezone UTC offset in - * minutes of the local machine. - * - * That value should then be used to calculate the effective timezone as - * string, but still that would be related to the machine and not to the - * specified date. - * - * For this reason we are completing date with "Z" TimeZoneDesignator (TZD) - * to say it to use local timezone. - * - * In the future we might think to integrate another parameter to represent - * a custom timezone. - * - * @see https://www.w3.org/TR/NOTE-datetime - */ - - return `${date.getFullYear()}-${paddedMonth}-${paddedDay}T${paddedHour}:${paddedMinutes}:${paddedSeconds}Z`; + return date.toISOString(); } function padMeTwo(original: string | number) { From 846d54d6811e71bb6f837114b82225740b00dc7a Mon Sep 17 00:00:00 2001 From: Jens Spanier Date: Tue, 8 Aug 2023 13:33:57 +0200 Subject: [PATCH 2/4] Fix tests --- specs/PKPass.spec.cjs | 8 ++++---- specs/utils.spec.cjs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/specs/PKPass.spec.cjs b/specs/PKPass.spec.cjs index beb8881..845360d 100644 --- a/specs/PKPass.spec.cjs +++ b/specs/PKPass.spec.cjs @@ -712,12 +712,12 @@ describe("PKPass", () => { describe("expiration date", () => { it("should set a pass expiration date", () => { - pkpass.setExpirationDate(new Date(2023, 3, 10)); + pkpass.setExpirationDate(new Date("2023-04-09T17:00-07:00")); const passjsonGenerated = getGeneratedPassJson(pkpass); expect(passjsonGenerated.expirationDate).toBe( - "2023-04-10T00:00:00Z", + "2023-04-10T00:00:00.000Z", ); }); @@ -808,11 +808,11 @@ describe("PKPass", () => { describe("relevant date", () => { it("should set pass relevant date", () => { - pkpass.setRelevantDate(new Date(2023, 3, 10, 14, 15)); + pkpass.setRelevantDate(new Date("2023-04-11T00:15+10:00")); const passjsonGenerated = getGeneratedPassJson(pkpass); - expect(passjsonGenerated.relevantDate).toBe("2023-04-10T14:15:00Z"); + expect(passjsonGenerated.relevantDate).toBe("2023-04-10T14:15:00.000Z"); }); it("should reset relevant date", () => { diff --git a/specs/utils.spec.cjs b/specs/utils.spec.cjs index 3636dd0..9a5ad3e 100644 --- a/specs/utils.spec.cjs +++ b/specs/utils.spec.cjs @@ -32,8 +32,8 @@ describe("Utils", () => { }); it("should convert a Date object to a valid W3C date", () => { - expect(processDate(new Date(2020, 6, 1, 0, 0, 0, 0))).toBe( - "2020-07-01T00:00:00Z", + expect(processDate(new Date("2020-07-01T02:00+02:00"))).toBe( + "2020-07-01T00:00:00.000Z", ); }); }); From 7fc263878ed627c56f6a164b84ba7bf2e106da5f Mon Sep 17 00:00:00 2001 From: Jens Spanier Date: Wed, 9 Aug 2023 08:19:00 +0200 Subject: [PATCH 3/4] Remove unused function --- src/utils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 578c483..3139625 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -39,10 +39,6 @@ function dateToW3CString(date: Date) { return date.toISOString(); } -function padMeTwo(original: string | number) { - return String(original).padStart(2, "0"); -} - /** * Removes hidden files from a list (those starting with dot) * From c80615351f705afd9c9b53c12f7a5dc9bdd72463 Mon Sep 17 00:00:00 2001 From: Jens Spanier Date: Wed, 9 Aug 2023 08:20:40 +0200 Subject: [PATCH 4/4] Add URL to W3C --- src/utils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index 3139625..a0110e6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -36,6 +36,10 @@ function dateToW3CString(date: Date) { return undefined; } + /** + * @see https://www.w3.org/TR/NOTE-datetime + */ + return date.toISOString(); }