New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
moment().fromNow() returns 'Invalid date' #4802
Comments
How do you run your Discord Bot? You said: "This worked before but it no longer works" Are you able to modify your discord bot code to show the output of the below (specifically using hard-coded strings): console.log('moment.format:', moment("2018-06-07T22:54:07.310Z").format());
console.log('moment.fromNow:', moment("2018-06-07T22:54:07.310Z").fromNow()); |
It was working before then just stopped. No code changed. No envirnoment changed with the bot. The way the dates are being parsed seem the same too. And here's what the console outputted;
and here's how I used it (
Not sure if I mentioned it or not, but here are the current versions I'm using: |
I'm having similar issue with Angular 6 (ionic based app) and moment 2.22.2 returns invalid date for something as simple as this. |
Still happening in 2.23.0
|
Thanks for opening this request It helps if you run these lines on your machines:
|
Thanks for the reply. I am using NodeJS, so there is not a navigator environment. new Date()).toString() Thu Jan 17 2019 06:53:11 GMT-0600 (Central Standard Time) I've been doing some testing and the conflict is an Object.prototype constructor.
|
I am also affected by this. |
Same problem here.
|
Same here on |
It's a hack, but you could change the console.log(moment().fromNow()); // 'a few seconds ago'
Object.prototype.randomExtension = true;
console.log(moment().fromNow()); // 'Invalid date'
Object.keys(Object.prototype).forEach(function(extension) {
Object.defineProperty(Object.prototype, extension, { enumerable: false });
});
console.log(moment().fromNow()); // 'a few seconds ago' |
Description of the Issue and Steps to Reproduce:
I'm using moment to get the age of a user's account, by using:
moment(user account created date here).fromNow()
but it return 'Invalid date'. This worked before but it no longer works. The created date looks something like:2018-06-07T22:54:07.310Z
.Using
moment(date here).format()
works fine.Please include the values of all variables used.
The date I use to format and use fromNow is
2018-06-07T22:54:07.310Z
Environment:
Discord Bot
Examples: Chrome 49 on OSX, Internet Explorer 10 on Windows 7, Node.JS 4.4.4 on Ubuntu 16.0.4
I don't use moment for anything listed above.
Both the browser and the OS are important to us, particularly if you have an unsual environment like an IOT application.
Other information that may be helpful: https://i.imgur.com/4LFsZh3.png
If you are reporting an issue, please run the following code in the environment you are using and include the output:
Sun Oct 07 2018 12:29:05 GMT-0700 (Pacific Daylight Time)
2018-10-7 12:29:05
420
2.22.2
Ensure your issue is isolated to moment. Issues involving third party tools will be closed unless submitted by the tool's author/maintainer.
The text was updated successfully, but these errors were encountered: