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

in wechart Mini Program always return America/Chicago #16

Open
TinkerDeng opened this issue May 8, 2018 · 9 comments
Open

in wechart Mini Program always return America/Chicago #16

TinkerDeng opened this issue May 8, 2018 · 9 comments

Comments

@TinkerDeng
Copy link

in wechart Mini Program always return America/Chicago, in browser return(Asia/Shanghai) is right

@iansinnott
Copy link
Owner

So jstz.determine().name() is returning America/Chicago even though it should return Asia/Shanghai?

What browser are you using?

@TinkerDeng
Copy link
Author

TinkerDeng commented May 9, 2018

image
wechart Developer Tools
This problem has been solved. I think is Developer Tools problem,In mobile is right.thank you very mush

@TinkerDeng
Copy link
Author

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

1525829609779

@xyxabcdiy
Copy link

+1

@iansinnott
Copy link
Owner

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

@xyxabcdiy
Copy link

xyxabcdiy commented May 10, 2018

@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.

@iansinnott
Copy link
Owner

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.

@TinkerDeng
Copy link
Author

Change the order of this method (datermine) is return right.I don't know if there are any other questions.
change before
image

change after
image
image

@iansinnott
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants