mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Removed moment for internal implementation
This commit is contained in:
5
package-lock.json
generated
5
package-lock.json
generated
@@ -179,11 +179,6 @@
|
|||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"moment": {
|
|
||||||
"version": "2.29.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
|
|
||||||
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
|
|
||||||
},
|
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "^4.3.1",
|
"debug": "^4.3.1",
|
||||||
"joi": "^17.3.0",
|
"joi": "^17.3.0",
|
||||||
"moment": "^2.29.1",
|
|
||||||
"node-forge": "^0.10.0",
|
"node-forge": "^0.10.0",
|
||||||
"tslib": "^2.1.0",
|
"tslib": "^2.1.0",
|
||||||
"yazl": "^2.5.1"
|
"yazl": "^2.5.1"
|
||||||
|
|||||||
@@ -76,12 +76,11 @@ describe("Passkit-generator", function () {
|
|||||||
expect(pass.props["expirationDate"]).toBe(undefined);
|
expect(pass.props["expirationDate"]).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Will set expiration with a Date as argument", () => {
|
it("expects a Date object as the only argument", () => {
|
||||||
pass.expiration(new Date(2020, 5, 1, 0, 0, 0));
|
pass.expiration(new Date(2020, 6, 1, 0, 0, 0, 0));
|
||||||
// this is made to avoid problems with winter and summer time:
|
// Month starts from 0 in Date Object when used this way, therefore
|
||||||
// we focus only on the date and time for the tests.
|
// we expect one month more
|
||||||
let noTimeZoneDateTime = pass.props["expirationDate"].split("+")[0];
|
expect(pass.props["expirationDate"]).toBe("2020-07-01T00:00:00Z");
|
||||||
expect(noTimeZoneDateTime).toBe("2020-06-01T00:00:00");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("An invalid date, will not apply changes", () => {
|
it("An invalid date, will not apply changes", () => {
|
||||||
@@ -96,12 +95,9 @@ describe("Passkit-generator", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("relevantDate()", () => {
|
describe("relevantDate()", () => {
|
||||||
it("A date object will apply changes", () => {
|
it("expects a Date object as the only argument", () => {
|
||||||
pass.relevantDate(new Date("10-04-2021"));
|
pass.relevantDate(new Date("10-04-2021"));
|
||||||
// this is made to avoid problems with winter and summer time:
|
expect(pass.props["relevantDate"]).toBe("2021-10-04T00:00:00Z");
|
||||||
// we focus only on the date and time for the tests.
|
|
||||||
let noTimeZoneDateTime = pass.props["relevantDate"].split("+")[0];
|
|
||||||
expect(noTimeZoneDateTime).toBe("2021-10-04T00:00:00");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -264,8 +260,8 @@ describe("Passkit-generator", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Will ignore non-Barcodes schema compliant objects", () => {
|
it("Will ignore non-Barcodes schema compliant objects", () => {
|
||||||
// @ts-expect-error
|
|
||||||
pass.barcodes(
|
pass.barcodes(
|
||||||
|
// @ts-expect-error
|
||||||
5,
|
5,
|
||||||
10,
|
10,
|
||||||
15,
|
15,
|
||||||
|
|||||||
35
src/utils.ts
35
src/utils.ts
@@ -1,4 +1,3 @@
|
|||||||
import moment from "moment";
|
|
||||||
import { EOL } from "os";
|
import { EOL } from "os";
|
||||||
import { PartitionedBundle, BundleUnit } from "./schema";
|
import { PartitionedBundle, BundleUnit } from "./schema";
|
||||||
import { sep } from "path";
|
import { sep } from "path";
|
||||||
@@ -41,13 +40,39 @@ export function dateToW3CString(date: Date) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedDate = moment(date).format();
|
// if it is NaN, it is "Invalid Date"
|
||||||
|
if (isNaN(Number(date))) {
|
||||||
if (parsedDate === "Invalid date") {
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedDate;
|
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`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function padMeTwo(original: string | number) {
|
||||||
|
return String(original).padStart(2, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user