Removed moment for internal implementation

This commit is contained in:
Alexander Cerutti
2021-02-09 14:16:19 +01:00
parent 9de5b3a0c4
commit 3e08d31d14
4 changed files with 38 additions and 23 deletions

View File

@@ -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");
}
/**