spencermountain / spacetime

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

Browser timezone cet/wet #192

Closed Chrischuck closed 4 years ago

Chrischuck commented 4 years ago

Related to this issue: https://github.com/spencermountain/spacetime/issues/181

But I'm getting this error Spacetime: Cannot find timezone named: 'cet'. Please enter an IANA timezone id. a lot in production on xiaomi devices.

I don't have any xiaomi devices or don't know how to repro this locally so it's been a shot in the dark to try and track this error down.

What I've done, since we use the IP to get the timezone on the server, is to make sure whenever spacetime is called, we pass it that timezone (which is IANA). so we'd always have spacetime.now(TIMEZONE) or spacetime(DATE, TIMEZONE).

Unfortunately, we still get this error, do you know any entry points that would cause this error to occur?

spencermountain commented 4 years ago

hi Chris, yeah, are you using some library to generate an Iana from the ip?

you can add a custom timezone like this: https://runkit.com/spencermountain/5e3d96db5accc10014e2d768

Chrischuck commented 4 years ago

I'm using maximind for the iana timezone, which I don't believe causes any errors.

If I add a custom timezone say at the entrypoint of my app, will that be reflected everywhere I import spacetime from?

spencermountain commented 4 years ago

ah, i don't actually know.

try to track it down. I'd be happy to at cet as a edge-case if it is coming from the device itself.

i just did a grep in spacetime and doubt it comes from us. Let me know!

Chrischuck commented 4 years ago

Will do @spencermountain, it's super odd and we've been battling this error for like a month...it ONLY happens on Xiaomi devices 🤦‍♀️

Chrischuck commented 4 years ago

@spencermountain I was finally able to repro this on firefox and it's happening when I add/subtract from the spacetime object. someTime.subtract(i, 'day');

I had to follow this

And then change the common name to "cet" so Intl.DateTimeFormat().resolvedOptions().timeZone would return "cet" in the browser.

Screen Shot 2020-02-22 at 8 53 12 PM

This is super edge case again and it's really been a thorn in our side since we haven't been able to repro until now. So thank you again for your help :)

Update

I'm a dummy, I wrapped spacetime in a function and forgot to pass the timezone into that function so it defaulted to browser TZ since it was undefined...

But I'm going going to leave this comment up so others know how to change their timezone to some of the unconventional stuff out there in the wild.

spencermountain commented 4 years ago

no sweat! good eye.