0

I have a script in cloud code in parse.com. And I'm trying to use moment-timezone.js because I need to convert the timezone of my installation from string (ie "Europe/Paris") to a time offset from UTC (GMT).

My code so far imported from this question :

var moment = require('cloud/moment.js');
var tz = require('cloud/moment-timezone.js');

function toTimeZone(time, zone) {
    var format = 'YYYY/MM/DD HH:mm:ss ZZ';
    return moment(time, format).tz(zone).format(format);
}

I have copied the latest moment.js and moment-timezone.js files from their website into my cloud directory.

Here is the error I get from log in cloud code :

Failed with: TypeError: Object Invalid date has no method 'tz'
at toTimeZone (main.js:6:30)
at query.find.success (main.js:19:17)
at Parse.js:2:10161
at e (Parse.js:2:8941)
at Parse.js:2:8390
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.resolve (Parse.js:2:8341)
at e (Parse.js:2:9076)
at Parse.js:2:8390
Community
  • 1
  • 1
Ambroise Collon
  • 3,839
  • 3
  • 18
  • 37

1 Answers1

0

According to Parse's documentation https://www.parse.com/docs/js/guide#cloud-code-modules-moment

You can try this:

var moment = require('cloud/moment');
var tz = require('cloud/moment-timezone');
Ralphilius
  • 1,746
  • 2
  • 16
  • 28