Start a new topic

`modules.moment().diff()` throws "TypeError: Cannot read property 'isValid' of undefined"

We had a bug report related to an area of code that hadn't been touched in a while. That endpoint was returning this:

```

{"error":"BLRuntimeError","description":"The Business Logic script has a runtime error. See debug message for details.","debug":"TypeError: Cannot read property 'isValid' of undefined"}

```



After investigating, it appears to calling `modules.moment().diff()` is the source of the problem. In our actual use case, we're passing an ISO date string into moment. Something like:



```

var iso = moment().toISOString();

moment(iso).diff();

```



Testing this out on moment.js works as expected. However, in Kinvey, it breaks even without passing an ISO string, so there doesn't seem to be any user-caused error.

Hi @brandly, I just wanted to let you know we're taking a look at this- our BL expert is out of pocket at the moment but we'll revert asap.
"Diff" is expecting a parameter to use to compare against. It can be another moment or string that matches a date. For example, to compare the start and stop time of some code:



`

var start = moment();

// ... do some work

var diff = moment().diff(start);

`



Another example, to get the difference between a specified date and the current moment:



`

var pointInTime = '2014-05-01T00:34:06+00:00';

var currentMoment = moment();

var diff = currentMoment.diff(pointInTime);

`
What version of moment.js is being exposed? Previously, running on Kinvey, the code I posted above worked as expected. And currently, in the console on momentjs.com, I can call `diff` without any arguments on an instance of `moment`, and it will return the difference between the current time and that moment.



http://i.imgur.com/Kqmmglz.jpg
It does appear to be a platform bug. I will tag it to be fixed in our next release of business logic.
Login or Signup to post a comment