jstz
jstz copied to clipboard
in wechart Mini Program always return America/Chicago
in wechart Mini Program always return America/Chicago, in browser return(Asia/Shanghai) is right
So jstz.determine().name()
is returning America/Chicago even though it should return Asia/Shanghai?
What browser are you using?
wechart Developer Tools
This problem has been solved. I think is Developer Tools problem,In mobile is right.thank you very mush
I met another problem. I want to add,such as Africa/Harare Africa/Addis_Ababa America/Indianapolis .But I don't know How to calculate
+1
This problem has been solved.
Glad to hear it 👍
Hm, i've never tried to use the lib in this way, but if you want to calculate the key for the timezones
object check out these comments: https://github.com/iansinnott/jstz/blob/master/jstz.main.js#L412-L418
@iansinnott Thank for your help!
There is another problem:
I found when I run jstz.determine().name()
in node.js, the result is Asia/Shanghai, but it should be America/Chicago.
I check the source code, if Intl.DateTimeFormat().resolvedOptions().timeZone
can return value, it will use this method to get timezone. But it not accurate in some cases.
Unfortunately, if Intl.DateTimeFormat().resolvedOptions().timeZone
is not accurate then there's nothing this lib can do. It will depend on what browser you're running in. I suspect some browsers handle the Intl.DateTimeFormat().resolvedOptions().timeZone
API differently than others.
Change the order of this method (datermine
) is return right.I don't know if there are any other questions.
change before
change after
That's interesting. It looks like get_from_internationalization_api()
is indeed returning a value, but it's not the expected value. This means that Intl.DateTimeFormat().resolvedOptions().timeZone
is returning the incorrect value.
It appears your solution works because it skips using the Intl
API and calculates lookup_key()
which is based on the Date
object. This method is meant to be a fallback only if the Intl
API is not supported in the browser, not an initial solution.
So it looks like your browser has the Intl
API but it returns the wrong timezone. This is unusual but there's not much you can do about it since you can't control what browser your users will be using.
On the other hand, if WeChat is you're only target platform then I would recommend forking this library and modifying it exactly as you suggested.