twix.js
twix.js copied to clipboard
TypeError: Cannot read property 'humanize' of undefined
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!
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.