vue-moment icon indicating copy to clipboard operation
vue-moment copied to clipboard

Allow numbers when specifying date format

Open rambii opened this issue 6 years ago • 1 comments

I want to transform months from format M to MMMM. The datatype is integer, which throws the error: Could not build a valid moment object from input.

Casting the integer to a string works but does not look really clean.

      {{ [ 2 + '', 'M' ] | moment('MMMM') }}  // displays "February" without an error
      {{ [ 2 , 'M' ] | moment('MMMM') }} // displays "[ 2 , 'M' ]" and logs error

I guess it is because the first value in an array is expected to be a string. Could number work there as well?

https://github.com/brockpetrie/vue-moment/blob/master/vue-moment.js#L20 Something like this: if (Array.isArray(input) && ['string', 'number'].includes(typeof input[0]))

rambii avatar May 22 '18 15:05 rambii

Yeah, that is definitely a valid input. Your solution should do the trick!

brockpetrie avatar Jul 18 '18 17:07 brockpetrie