Adding support for native Dates (#32) by Ianbale

This commit is contained in:
Ian Bale
2019-06-07 11:42:28 +01:00
committed by Alexander Cerutti
parent a0a02bf083
commit bc941640fc
3 changed files with 24 additions and 3 deletions

View File

@@ -259,7 +259,7 @@ class Pass {
*/
expiration(date, format) {
if (typeof date !== "string") {
if (typeof date !== "string" && !(date instanceof Date)) {
return this;
}
@@ -327,6 +327,11 @@ class Pass {
return assignLength(Number(!cond), this);
} else if (type === "relevantDate") {
if (typeof data !== "string" && !(data instanceof Date)) {
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
return this;
}
let dateParse = dateToW3CString(data, relevanceDateFormat);
if (!dateParse) {

View File

@@ -34,11 +34,11 @@ function isValidRGB(value) {
*/
function dateToW3CString(date, format) {
if (typeof date !== "string") {
if (typeof date !== "string" && !(date instanceof Date)) {
return "";
}
const parsedDate = moment(date.replace(/\//g, "-"), format || ["MM-DD-YYYY hh:mm:ss", "DD-MM-YYYY hh:mm:ss"]).format();
const parsedDate = date instanceof Date ? moment(date).format() : moment(date.replace(/\//g, "-"), format || ["MM-DD-YYYY hh:mm:ss", "DD-MM-YYYY hh:mm:ss"]).format();
if (parsedDate === "Invalid date") {
return undefined;