3

I have problem using all 3 of the packages together. I define them like this:

var moment = require('moment-timezone');
var momentRange = require('moment-range');

And when I want to use the moment-range functions, I'm trying to call it like this:

var range1 = momentRange.range(moment("string1"), moment("string2"));

And I'm getting error: TypeError: momentRange.range is not a function

What am I doing wrong?

svarog
  • 9,477
  • 4
  • 61
  • 77

1 Answers1

8

According to the documentation, you are supposed to use the moment-range library to first extend the core moment library itself, then use moment.range because the moment-range package adds additional functions to the moment object:

var momentRange = require('moment-range');
momentRange.extendMoment(moment);

moment.range(moment(…), moment(…)); // Now usable

Specifically, in their documentation:

CommonJS:

const Moment = require('moment');
const MomentRange = require('moment-range');

const moment = MomentRange.extendMoment(Moment);
Community
  • 1
  • 1
Andrew Li
  • 55,805
  • 14
  • 125
  • 143