Skip to content
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

overflowing moment seen as valid #5075

Open
aronatkins opened this issue Apr 12, 2019 · 1 comment
Open

overflowing moment seen as valid #5075

aronatkins opened this issue Apr 12, 2019 · 1 comment
Labels

Comments

@aronatkins
Copy link

Describe the bug

Given a valid moment, subtract some massive duration from that moment. The moment declares that isValid()==true but gives "Invalid date" when converted to a string.

To Reproduce

<html>
    <head>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
        <script type="text/javascript">
         m = moment();
         m.add(1000000, "years");
         console.log("valid: "+m.isValid());
         console.log("before 1980: "+m.isBefore('1980-01-01T00:00:00.000Z'));
         console.log("after 1980: "+m.isAfter('1980-01-01T00:00:00.000Z'));
         console.log("as string: "+m.toString());
         // => "Invalid date"
        </script>

        <script type="text/javascript" >
            console.log((new Date()).toString())
            console.log((new Date()).toLocaleString())
            console.log((new Date()).getTimezoneOffset())
            console.log(navigator.userAgent)
            console.log(moment.version)
        </script>            
    </head>
    <body>
    </body>
</html>
valid: true
before 1980: false (moment.html, line 8)
after 1980: false (moment.html, line 9)
as string: Invalid date (moment.html, line 10)

Expected behavior

If a moment is manipulated in such a way to make it overflow, isValid should return false.

Desktop

  • OS: macOS (tested multiple browsers)

  • Browser Safari

  • Version 12.1

  • Browser Chrome

  • Version 73.0.3683.103

Moment-specific environment

  • The time zone setting of the machine the code is running on
  • The time and date at which the code was run
  • Other libraries in use (TypeScript, Immutable.js, etc)

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(moment.version)
Fri Apr 12 2019 17:10:50 GMT-0400 (Eastern Daylight Time)
4/12/2019, 5:10:50 PM
240
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
2.24.0
@nishantgupta204
Copy link

How did you use add method? I did not find method in moment object

@marwahaha marwahaha added the Bug label May 18, 2020
Alanscut added a commit to Alanscut/moment that referenced this issue May 20, 2020
ichernev added a commit that referenced this issue Dec 23, 2023
[bugfix] Fix issue #5075, Delete destructive judgment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants