Added expiration() and void() methods and dateToW3CString() function to convert date in W3C format

This commit is contained in:
alexandercerutti
2018-08-19 15:57:14 +02:00
parent d97e1c6ab7
commit 769d75cb88

View File

@@ -160,6 +160,40 @@ class Pass {
return Buffer.from(strings.join("\n"), "utf8"); return Buffer.from(strings.join("\n"), "utf8");
} }
/**
* Sets expirationDate property to the W3C date
*
* @method expiration
* @params {String} date - the date in string
* @returns {this}
*/
expiration(date) {
if (typeof date !== "string") {
return this;
}
const convDate = dateToW3CString(date);
if (convDate) {
this.props.expirationDate = convDate;
}
return this;
}
/**
* Sets voided property to true
*
* @method void
* @return {this}
*/
void() {
this.props.voided = true;
return this;
}
/** /**
* Checks if pass model type is one of the supported ones * Checks if pass model type is one of the supported ones
* *
@@ -406,6 +440,27 @@ class Pass {
} }
} }
/**
* Converts a date to W3C Standard format
*
* @function dateToW3Cstring
* @params {String}
*/
function dateToW3CString(date) {
if (typeof date !== "string") {
return "";
}
let parsedDate = moment(date, ["MM-DD-YYYY"]).format();
if (parsedDate === "Invalid date") {
return "";
}
return parsedDate;
}
/** /**
* Apply a filter to arg0 to remove hidden files names (starting with dot) * Apply a filter to arg0 to remove hidden files names (starting with dot)
* @function removeHidden * @function removeHidden