mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Removed String-Date and its format on methods that uses dates for native Date object
This commit is contained in:
20
src/pass.ts
20
src/pass.ts
@@ -183,17 +183,16 @@ export class Pass implements PassIndexSignature {
|
|||||||
* Sets expirationDate property to the W3C date
|
* Sets expirationDate property to the W3C date
|
||||||
*
|
*
|
||||||
* @method expiration
|
* @method expiration
|
||||||
* @params {String} date - the date in string
|
* @params date
|
||||||
* @params {String} format - a custom format for the date
|
|
||||||
* @returns {this}
|
* @returns {this}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
expiration(date: string | Date, format?: string) {
|
expiration(date: Date) {
|
||||||
if (typeof date !== "string" && !(date instanceof Date)) {
|
if (!(date instanceof Date)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dateParse = dateToW3CString(date, format);
|
const dateParse = dateToW3CString(date);
|
||||||
|
|
||||||
if (!dateParse) {
|
if (!dateParse) {
|
||||||
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Expiration date"));
|
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Expiration date"));
|
||||||
@@ -221,13 +220,12 @@ export class Pass implements PassIndexSignature {
|
|||||||
* Checks and sets data for "beacons", "locations", "maxDistance" and "relevantDate" keys
|
* Checks and sets data for "beacons", "locations", "maxDistance" and "relevantDate" keys
|
||||||
*
|
*
|
||||||
* @method relevance
|
* @method relevance
|
||||||
* @params {String} type - one of the key above
|
* @params type - one of the key above
|
||||||
* @params {Any[]} data - the data to be pushed to the property
|
* @params data - the data to be pushed to the property
|
||||||
* @params {String} [relevanceDateFormat] - A custom format for the date
|
|
||||||
* @return {Number} The quantity of data pushed
|
* @return {Number} The quantity of data pushed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
relevance(type: string, data: any, relevanceDateFormat?: string) {
|
relevance(type: string, data: any) {
|
||||||
let types = ["beacons", "locations", "maxDistance", "relevantDate"];
|
let types = ["beacons", "locations", "maxDistance", "relevantDate"];
|
||||||
|
|
||||||
if (!type || !data || !types.includes(type)) {
|
if (!type || !data || !types.includes(type)) {
|
||||||
@@ -257,12 +255,12 @@ export class Pass implements PassIndexSignature {
|
|||||||
|
|
||||||
return assignLength(Number(!cond), this);
|
return assignLength(Number(!cond), this);
|
||||||
} else if (type === "relevantDate") {
|
} else if (type === "relevantDate") {
|
||||||
if (typeof data !== "string" && !(data instanceof Date)) {
|
if (!(data instanceof Date)) {
|
||||||
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
|
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dateParse = dateToW3CString(data, relevanceDateFormat);
|
let dateParse = dateToW3CString(data);
|
||||||
|
|
||||||
if (!dateParse) {
|
if (!dateParse) {
|
||||||
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
|
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date"));
|
||||||
|
|||||||
11
src/utils.ts
11
src/utils.ts
@@ -27,18 +27,17 @@ export function isValidRGB(value: string): boolean {
|
|||||||
* Converts a date to W3C Standard format
|
* Converts a date to W3C Standard format
|
||||||
*
|
*
|
||||||
* @function dateToW3Cstring
|
* @function dateToW3Cstring
|
||||||
* @params {String} date - The date to be parsed
|
* @params date - The date to be parsed
|
||||||
* @params {String} [format] - a custom format
|
* @returns - The parsed string if the parameter is valid,
|
||||||
* @returns {String|undefined} The parsed string if the parameter is valid,
|
|
||||||
* undefined otherwise
|
* undefined otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function dateToW3CString(date: string | Date, format?: string) {
|
export function dateToW3CString(date: Date) {
|
||||||
if (typeof date !== "string" && !(date instanceof Date)) {
|
if (!(date instanceof Date)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
const parsedDate = moment(date).format();
|
||||||
|
|
||||||
if (parsedDate === "Invalid date") {
|
if (parsedDate === "Invalid date") {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user