mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Unified date processing of expiration and relevantDate
This commit is contained in:
39
src/pass.ts
39
src/pass.ts
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user