Unified date processing of expiration and relevantDate

This commit is contained in:
Alexander Cerutti
2019-06-29 17:50:50 +02:00
parent a981571c42
commit b410a435df

View File

@@ -243,15 +243,12 @@ export class Pass implements PassIndexSignature {
return this; return this;
} }
const dateParse = dateToW3CString(date); const parsedDate = processDate("expirationDate", date);
if (!dateParse) { if (parsedDate) {
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Expiration date")); this._props["expirationDate"] = parsedDate;
return this;
} }
this._props["expirationDate"] = dateParse;
return this; return this;
} }
@@ -349,19 +346,12 @@ export class Pass implements PassIndexSignature {
return this; return this;
} }
if (!(date instanceof Date)) { const parsedDate = processDate("relevandDate", date);
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
return this; if (parsedDate) {
this._props["relevantDate"] = parsedDate;
} }
const parsedDate = dateToW3CString(date);
if (!parsedDate) {
// @TODO: create message "Unable to format date"
return this;
}
this._props["relevantDate"] = parsedDate;
return this; return this;
} }
@@ -693,3 +683,18 @@ function barcodesFromUncompleteData(message: string): schema.Barcode[] {
"PKBarcodeFormatCode128" "PKBarcodeFormatCode128"
].map(format => schema.getValidated({ format, message }, "barcode")); ].map(format => schema.getValidated({ format, message }, "barcode"));
} }
function processDate(key: string, date: Date): string | null {
if (!(date instanceof Date)) {
return null;
}
const dateParse = dateToW3CString(date);
if (!dateParse) {
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", key));
return null;
}
return dateParse;
}