As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
`modules.moment().diff()` throws "TypeError: Cannot read property 'isValid' of undefined"
b
brandly
started a topic
about 9 years ago
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.
M
Michael
said
almost 9 years ago
"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);
`
b
brandly
said
almost 9 years ago
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
M
Michael
said
almost 9 years ago
It does appear to be a platform bug. I will tag it to be fixed in our next release of business logic.
brandly
```
{"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.