Vue.js: console warning with vue-moment with firebase dates from authentication - date updated

Viewed 6025

Moment is returning what I want...

Date updated: 41 minutes ago

But I get Chrome console warning: Could not build a valid `moment` object from input.


Date coming from Firebase in this format

dateUpdate:

2018-10-25T17:33:24.537Z

profile.vue

<span>Date updated: {{ dateUpdated | moment("from", "now") }}</span>

Question How do I suppress this error?

(it seems that the Firebase date is not valid for moment.js)

vue-moment.js

  if (!input || !date.isValid()) {
    // Log a warning if moment couldn't reconcile the input. Better than throwing an error?
    console.warn('Could not build a valid `moment` object from input.');
    return input;
  }

Thanks,

1 Answers

What happens if you do:

<span>{{ [ dateUpdated, "YYYY-MM-DDTHH:mm:ss.SSS" ] | moment("dddd, MMMM Do YYYY") }}</span>

See http://momentjs.com/docs/#/parsing/special-formats/

The following "simple" JavaScript prints true in the console, using the "standard" moment.js library:

var sDate = "2018-10-25T17:33:24.537Z";
var mDate = moment(sDate, "YYYY-MM-DDTHH:mm:ss.SSS");
console.log(mDate.isValid());
Related