1

I am using backgrid to display JSON results from the backend Db. One of the fields is time in seconds from 1970 (eg. 1362578461000) when the Backbone view receives this data backgrid sends it off to moment for formating. Moment then throws a javaScript TypeError exception indicated on line 758 of Moment.js (v.2.0.0)

TypeError: string.indexOf is not a function

The column format looks like this:

            var columns = [{
            name: "startTime",
            label: "Start Time",
            editable: false,
            cell: "moment"
        }, {
            name: "endTime",
            label: "End Time",
            editable: false,
            cell: "moment"
        }];

Putting a brakepoint in Firebug it looks like Moment thinks that the value is a integer rather then a string.

utc()moment.js (line 960)

input = 1362578461000

format = "YYYY-MM-DDTHH:mm:ssZ"

lang = undefined

And the call to makeDateFromStringAndFormat looks like this:

makeDateFromStringAndFormat()moment.js (line 758) config = Object { _useUTC=true, _isUTC=true, _i=1362578461000, more...}

Any ideas as to what I can do to fix/get around this?

Thanks

Community
  • 1
  • 1
Paul
  • 217
  • 3
  • 12

1 Answers1

1

Author of Backgrid here. There are 2 parts to your question:

  1. Backgrid.js has only gained compatibility with moment.js 2.0.0 in 0.2.5 released yesterday.
  2. The moment cell doesn't accept integers as input in the model because it tries to convert timezones and locales, so your model values have to be in a datetime string format that moment knows how to parse.
Y.H Wong
  • 7,151
  • 3
  • 33
  • 35