mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Adding support for native Dates (#32) by Ianbale
This commit is contained in:
committed by
Alexander Cerutti
parent
a0a02bf083
commit
bc941640fc
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user