mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Changed processDate function to throw if it cannot complete conversion
This commit is contained in:
@@ -698,15 +698,13 @@ export default class PKPass extends Bundle {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedDate = processDate("expirationDate", date);
|
try {
|
||||||
|
this[propsSymbol]["expirationDate"] = processDate(date);
|
||||||
if (!parsedDate) {
|
} catch (err) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Cannot set expirationDate. Invalid date ${date}`,
|
`Cannot set expirationDate. Invalid date ${date}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this[propsSymbol]["expirationDate"] = parsedDate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -789,15 +787,13 @@ export default class PKPass extends Bundle {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedDate = processDate("relevantDate", date);
|
try {
|
||||||
|
this[propsSymbol]["relevantDate"] = processDate(date);
|
||||||
if (!parsedDate) {
|
} catch (err) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Cannot set relevantDate. Invalid date ${date}`,
|
`Cannot set relevantDate. Invalid date ${date}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this[propsSymbol]["relevantDate"] = parsedDate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,16 +26,15 @@ export function isValidRGB(value?: string): boolean {
|
|||||||
return rgb.slice(1, 4).every((v) => Math.abs(Number(v)) <= 255);
|
return rgb.slice(1, 4).every((v) => Math.abs(Number(v)) <= 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function processDate(key: string, date: Date): string | null {
|
export function processDate(date: Date): string | null {
|
||||||
if (!(date instanceof Date)) {
|
if (!(date instanceof Date)) {
|
||||||
return null;
|
throw "Invalid date";
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateParse = dateToW3CString(date);
|
const dateParse = dateToW3CString(date);
|
||||||
|
|
||||||
if (!dateParse) {
|
if (!dateParse) {
|
||||||
console.warn(formatMessage(DEBUG.DATE_FORMAT_UNMATCH, key));
|
throw "Invalid date";
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dateParse;
|
return dateParse;
|
||||||
|
|||||||
Reference in New Issue
Block a user