From 46597d275dca817f588c630c9002fb6bd5367ac3 Mon Sep 17 00:00:00 2001 From: Brock Petrie Date: Sat, 2 Dec 2017 00:07:36 -0600 Subject: [PATCH 1/2] Treat Number input as Unix time --- readme.md | 6 +++--- vue-moment.js | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 4a6db1c..3fa5c8b 100644 --- a/readme.md +++ b/readme.md @@ -5,13 +5,13 @@ Handy [Moment.js](http://www.momentjs.com) filters for your [Vue.js](http://vuej ## Installation -Install via NPM and +Install via NPM... ```sh $ npm install vue-moment ``` -Require the plugin like so: +...and require the plugin like so: ```js Vue.use(require('vue-moment')); @@ -29,7 +29,7 @@ Simply set `moment` as the filtering function and you're good to go. At least on ## Passing Your Date -Moment.js expects your input to be either: a valid ISO 8601 formatted string (see ), a valid `Date` object, or a date string with an accompanying format pattern (i.e. when you know the format of the date input). For the latter, `vue-moment` allows you to pass your date and format pattern(s) as an array, like such: +Moment.js expects your input to be either: a valid ISO 8601 formatted string (see ), a valid `Date` object, a Unix timestamp (must be passed as a Number), or a date string with an accompanying format pattern (i.e. when you know the format of the date input). For the latter, `vue-moment` allows you to pass your date and format pattern(s) as an array, like such: ```html {{ [ someDate, "MM.DD.YY" ] | moment("dddd, MMMM Do YYYY") }} diff --git a/vue-moment.js b/vue-moment.js index 15ee701..74b5092 100644 --- a/vue-moment.js +++ b/vue-moment.js @@ -26,6 +26,9 @@ module.exports = { // Format pattern will accept an array of potential formats to parse against. // Date string should be at [0], format pattern(s) should be at [1] date = moment(string = input[0], formats = input[1], true); + } else if (typeof input === 'number') { + // If input is an integer, assume it's a Unix timestamp. + date = moment.unix(input); } else { // Otherwise, throw the input at moment and see what happens... date = moment(input); From 1f6aede5c471c8350145d3bfffb0e573a1346473 Mon Sep 17 00:00:00 2001 From: Brock Petrie Date: Sat, 2 Dec 2017 00:18:57 -0600 Subject: [PATCH 2/2] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fd6f47..ae3a01b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-moment", - "version": "3.0.0", + "version": "3.1.0", "description": "Handy Moment.js filters for your Vue.js project", "main": "vue-moment.js", "scripts": {