diff --git a/index.js b/index.js index 1ba8e98..6a4a088 100644 --- a/index.js +++ b/index.js @@ -160,6 +160,40 @@ class Pass { 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 * @@ -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) * @function removeHidden