Skip to content

Commit

Permalink
Merge pull request #58 from brockpetrie/unix-time
Browse files Browse the repository at this point in the history
Treat Number input as Unix time
  • Loading branch information
brockpetrie authored Dec 2, 2017
2 parents 08c474a + 1f6aede commit 649ccb8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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 <http://momentjs.com/docs/#/parsing/string/>), 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 <http://momentjs.com/docs/#/parsing/string/>), 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
<span>{{ [ someDate, "MM.DD.YY" ] | moment("dddd, MMMM Do YYYY") }}</span>
Expand Down
3 changes: 3 additions & 0 deletions vue-moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 649ccb8

Please sign in to comment.