icambron / twix.js

:hourglass::left_right_arrow: A date range plugin for moment.js
https://isaaccambron.com/twix.js/
MIT License
379 stars 54 forks source link

TypeError: Cannot read property 'humanize' of undefined #116

Open Nantris opened 4 years ago

Nantris commented 4 years ago

It seems really weird, because simpleFormat works fine, but humanizeLength invariably fails with the error TypeError: Cannot read property 'humanize' of undefined

const getText = timeToAdd => {
  const now = moment();
  const reminderTime = moment().add(timeToAdd, 'minutes');
  const range = now.twix(reminderTime.format()); //  range is a time span from the current time to the reminderTime
   const humanized = range.humanizeLength();  //  Fails with "TypeError: Cannot read property 'humanize' of undefined"
  // const humanized = range.simpleFormat();  //  Works fine
  return humanized;
};

Any thoughts? Thanks for this great project!

icambron commented 4 years ago

It seems like that error would be somewhere in Moment. Twix is essentially doing this:

var startMoment = range.start();
var endMoment = range.end();
startMoment.from(endMoment);

And somehow, I'm guessing, inside of Moment's from, there's an error calling humanize internally. I can't imagine why that would happen, though.