jtsage / jtsage-datebox

A multi-mode date and time picker for Bootstrap (3&4), jQueryMobile, Foundation, Bulma, FomanticUI, and UIKit (or others)
http://datebox.jtsage.dev/
Other
474 stars 166 forks source link

Error (NaN) when entering long values ​​in inputs. #345

Closed tiunov80 closed 10 years ago

tiunov80 commented 10 years ago

Tested in win8, chrome. Could you help our team with this problem? http://screencast.com/t/sPJ5TFuhv Thanks

jtsage commented 10 years ago

Well,

short answer - no, not really.

long answer - it's not actually my error. In order for the time to count correctly, I use the underlying javascript date function (there isn't really a different way to handle the date functions - to do time, it would require a lot of extra math). Anyway, long story short, when you put in a sufficiently large value, you are overrunning the internal date object.

At a glance, the minimum date is something like:

Mon Apr 19 -271821 20:00:00 GMT-0400 (EDT) (-8640000000000000ms)

and the max is something like:

Fri Sep 12 275760 20:00:00 GMT-0400 (EDT) (8640000000000000ms)

Interestingly, in my little bit of testing with chrome, it won't invalidate an under-run date - it just set's it to the minimum. Add a millisecond to the max, and you get "Invalid Date".

You are adding 3,564,644,542 Hours in your example, which is

12,832,720,351,200,000
 8,640,000,000,000,000 (min/max)
     1,415,203,410,418 (NOW() (ish))

As you can probably see, the amount you are trying to add is way over the min/max, without even taking into account the current value. I know that this is the min/max value on chrome - I've no idea what other implementations might have done.