Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for numbers when passing an array of date & format #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/vue-moment.spec.js
Expand Up @@ -253,6 +253,16 @@ describe('VueMoment', () => {
});
});

it('handles array', (done) => {
vm.now = [7, 'M'];
vm.args = ['MMMM'];
vm.$nextTick(() => {
expect(console.warn).not.toBeCalled();
expect(vm.$el.textContent).toContain('July');
done();
});
});

it('handles Date object', (done) => {
vm.now = new Date(2017, 0, 1);
vm.args = ['YYYY-MM-DD'];
Expand Down
4 changes: 2 additions & 2 deletions vue-moment.js
Expand Up @@ -17,10 +17,10 @@ module.exports = {
const input = args.shift();
let date;

if (Array.isArray(input) && typeof input[0] === 'string') {
if (Array.isArray(input) && ['string', 'number'].includes(typeof input[0])) {
// If input is array, assume we're being passed a format pattern to parse against.
// 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 should be at [0], format pattern(s) should be at [1]
date = moment(input[0], input[1], true);
} else if (typeof input === 'number') {
if (input.toString().length < 12) {
Expand Down