moment doesn't seem to parse date objects

  • I'm having a weird experience using moment in jsReport to parse dates. The moment library works fine for this example in the node REPL or my node projects, but in jsReport it doesn't seem to want to work.

    Not sure if anyone's encountered this before.

    I set up a simple example in the jsreport playground:

  • Solution...

    Don't pass Date instance to the moment factory function. Use getTime instead

    const moment = require('moment');
    const jsDate = new Date(2016, 0, 1);
    return moment(jsDate.geTime()).format('YYYY-MM-DD')

    Why? We use sandboxing library to evaluate your javascript. For security reason. And there seems to be a problem with it.
    I submitted the issue and we will try to communicate it with the author and see how we can proceed.

  • Thanks for the response. It's pretty strange. In the mean time I'll use the workaround.

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.