mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 20:25:26 +00:00
Removed moment for internal implementation
This commit is contained in:
35
src/utils.ts
35
src/utils.ts
@@ -1,4 +1,3 @@
|
||||
import moment from "moment";
|
||||
import { EOL } from "os";
|
||||
import { PartitionedBundle, BundleUnit } from "./schema";
|
||||
import { sep } from "path";
|
||||
@@ -41,13 +40,39 @@ export function dateToW3CString(date: Date) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const parsedDate = moment(date).format();
|
||||
|
||||
if (parsedDate === "Invalid date") {
|
||||
// if it is NaN, it is "Invalid Date"
|
||||
if (isNaN(Number(date))) {
|
||||
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