twix.js icon indicating copy to clipboard operation
twix.js copied to clipboard

TypeError: Cannot read property 'humanize' of undefined

Open Nantris opened this issue 6 years ago • 1 comments

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!

Nantris avatar Dec 13 '19 23:12 Nantris

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.

icambron avatar Dec 14 '19 05:12 icambron