spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.99k stars 183 forks source link

Safari date-object issues #176

Open johnfumaster opened 4 years ago

johnfumaster commented 4 years ago

Error

undefined is not an object (evaluating 'this.epoch=null')

I'm receiving errors from our monitoring software that people are experiencing. I don't know what's causing it. I've thrown invalid dates, invalid strings, NaN into spacetime(), and I can't get it to throw this error.

The line reports is coming from: webpack:///./node_modules/spacetime/builds/spacetime.js:3826:0:in 'epoch'

spencermountain commented 4 years ago

thanks john, that sounds weird. Are you using it with .bind() or something? it's a pretty generic this call. this should always exist, unless being called in a fancy way.

johnfumaster commented 4 years ago

No, not any special way. I am doing something like this mostly. spacetime(date).isValid()

where date can be of new Date(), new Date('2016-01-01'), a number like 1488370835081, NaN, null, undefined etc.

johnfumaster commented 4 years ago

I've just put in a try catch around the call to instantiate a spacetime to log the input that is causing the error. I'll let you know my findings as soon as I find out.

johnfumaster commented 4 years ago

Ok. Here's what caused the errors. The code was instantiating with: let s = spacetime(”2019-11-21”) As well as let a = spacetime("Thu Nov 21 2019 15:48:12 GMT+1100 (AEDT)")

They seem to produce dates, it's just that spacetime code throws an error for some bizarre reason.

Any ideas?

johnfumaster commented 4 years ago

Hi, we can finally replicate the error. It seems to be an issue with Safari 11 on desktop. I can't replicate the error everytime I load, but it is happening intermittently on Safari 11

spencermountain commented 4 years ago

thanks John, that's really helpful. I'm happy to fix this. The second date appears not parse into a valid date. If there's a weird browser issue, we should be able to set some kind of guard or polyfill.

what are the actual method calls, to reproduce it?

spencermountain commented 4 years ago

yeah, it seems safari has some opinions in it's Date Object. That could be it. Either way, the no-this error shouldn't happen. We should figure it out. cheers

johnfumaster commented 4 years ago

Thanks Spencer. Much appreciated.

The stack overflow only reports issues with 'yyyy-MM-dd' format. But we are also getting errors when using 1574312228115 and Mon Nov 25 2019 11:00:00 GMT+1100 (AEDT).