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

TimeZoneInfo.GetSystemTimeZones produces unexpected results in Blazor WASM for .NET 5 #44840

Closed
andersme opened this issue Nov 17, 2020 · 19 comments
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono
Milestone

Comments

@andersme
Copy link

Describe the bug

When using TimeZoneInfo.GetSystemTimeZones method in Blazor WASM on .NET 5, I am getting a strange list returned.

image

  • The list is much shorter than I would expect, and appears to be missing many time zones. I even show, in my example, my current time zone, which is missing from the list.
  • The display names are not very good and not something I would want to show an end user.

Is there any other method to return all available time zones that I am not aware of?

To Reproduce

Use TimeZoneInfo.GetSystemTimeZones inside of a Blazor WASM page with .NET 5.

@andersme andersme reopened this Nov 17, 2020
@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore Nov 17, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Nov 17, 2020
@andersme andersme changed the title TimeZoneInfo.GetSystemTimeZones produces strange results in Blazor WASM for .NET 5 TimeZoneInfo.GetSystemTimeZones produces unexpected results in Blazor WASM for .NET 5 Nov 18, 2020
@lewing lewing added arch-wasm WebAssembly architecture and removed untriaged New issue has not been triaged by the area owner labels Nov 18, 2020
@lewing
Copy link
Member

lewing commented Nov 18, 2020

Some timezone information has been reduced or removed to save size in the deployed app. There are some options to resolve this but we'd be interested to know what use case you are trying to support?

@andersme
Copy link
Author

I'm currently just trying to allow users to select a time zone for their company in my application I'm building. How can I get the full time zone information, if it's not enabled by default?

@rogihee
Copy link

rogihee commented Nov 18, 2020

See https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-5.0#localization.

Note that this will significantly increase your download size. I think there is still some work with sharding.

I ran into the same issue, I just generate a list on the server and let the user pick from there in the edit form. For date time formats and utc offset, I keep a user model on a singleton service that updates the format for other services for displaying dates, user avatar menu etc. This user model is updated after login.

@andersme
Copy link
Author

See https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-5.0#localization.

Note that this will significantly increase your download size. I think there is still some work with sharding.

I ran into the same issue, I just generate a list on the server and let the user pick from there in the edit form. For date time formats and utc offset, I keep a user model on a singleton service that updates the format for other services for displaying dates, user avatar menu etc. This user model is updated after login.

Interestingly enough, I tried the documentation you referenced there, and it doesn't seem to fix the issue. Perhaps I'm doing something wrong.

It is really unfortunate that we have to roll our own time zone lists but I guess that's the only viable option here.

@ghost
Copy link

ghost commented Nov 18, 2020

Tagging subscribers to this area: @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

Issue Details

Describe the bug

When using TimeZoneInfo.GetSystemTimeZones method in Blazor WASM on .NET 5, I am getting a strange list returned.

image

  • The list is much shorter than I would expect, and appears to be missing many time zones. I even show, in my example, my current time zone, which is missing from the list.
  • The display names are not very good and not something I would want to show an end user.

Is there any other method to return all available time zones that I am not aware of?

To Reproduce

Use TimeZoneInfo.GetSystemTimeZones inside of a Blazor WASM page with .NET 5.

Author: andersme
Assignees: tqiu8
Labels:

arch-wasm, area-VM-meta-mono

Milestone: -

@lewing
Copy link
Member

lewing commented Nov 19, 2020

@tqiu8 can you take a look at this. It seems like the list filtering is causing issues and we should possibly revisit that choice.

@tqiu8
Copy link
Contributor

tqiu8 commented Nov 19, 2020

@lewing the list filtering is definitely limiting the system timezones; however for the problem of the display names I believe it's because the StandardName might've been used instead of DisplayName. I can disable the filtering.

@lewing
Copy link
Member

lewing commented Nov 19, 2020

@tqiu8 I suspect the name is coming from icu and has been removed there but please verify. It's possible we can fix that part with the included data

@lewing
Copy link
Member

lewing commented Nov 19, 2020

@andersme finding the right size/feature/time balance is difficult but feedback is appreciated.

If it is of any help we can point you to the parts of the build process that construct this data.

@andersme
Copy link
Author

andersme commented Nov 19, 2020

@lewing I simply want the option to be able to get the complete list of time zones. I understand that this may cause additional load size, but that's okay. I guess I also would like to understand what the differences is between .NET Core 3.1 and .NET 5, because the list return in .NET Core 3.1 seems much more comprehensive.

@tqiu8
Copy link
Contributor

tqiu8 commented Nov 24, 2020

The DisplayName problem is described in this issue: #16232

@flacodirt
Copy link

Here is the complete output from my client side logging using v5.0.2, it produced 14 time zones. The same test on server side produced 140 time zones.

foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
     _logger.LogInformation(z.Id);
  1. America/Los_Angeles
  2. America/St_Johns
  3. America/Argentina/Catamarca
  4. America/Sao_Paulo
  5. UTC
  6. Europe/London
  7. Europe/Lisbon
  8. Europe/Berlin
  9. Africa/Tripoli
  10. Africa/Nairobi
  11. Europe/Moscow
  12. Australia/Perth
  13. Australia/Sydney
  14. Pacific/Tongatapu

@mattjohnsonpint
Copy link
Contributor

I believe this issue has been resolved for .NET 6 with #48931 and #50650

@nssidhu
Copy link

nssidhu commented May 17, 2021

currentTimeZone = TimeZoneInfo.Local;
Even this is returning Incorrect Result ( I am in Chicago), but this returns 'America/Los_Angeles'.

So it means i will have to wait to .NET 6 is released, don't want to use Preview version as this is problem occurring in production, will use some other method to fix it.
Looks like everything related to Timezone is broken in .NET 5

@mattjohnsonpint
Copy link
Contributor

@nssidhu - That's a slightly different area than what this issue is about. However, I assume you are still talking about Blazor WASM? If so, TimeZoneInfo.Local.Id should be the same as would be given by Intl.DateTimeFormat().resolvedOptions().timeZone in JavaScript (which reflects your system time zone settings). Please check and let us know if they differ.

Note, this part of .NET on WASM works the same way in .NET 5 and 6. There's some minor refactoring between, but in both cases the time zone is read using the ECMAScript Intl API.

@nssidhu
Copy link

nssidhu commented May 18, 2021

Confirming that both are giving the same value 'America/Los_Angeles'.
Next question why am getting incorrect value ? i expect to get CST- Chicago Time Zone

@nssidhu
Copy link

nssidhu commented May 18, 2021

Hmm, currentTimeZone = TimeZoneInfo.Local; this turned out to be system setting on the VM that code was running on. It was set to PST

@CoffeeFlux CoffeeFlux added this to the 6.0.0 milestone Jun 14, 2021
@CoffeeFlux
Copy link
Contributor

It seems like this is fixed for net6, so closing. If there's anything actionable left, let me know and I can reopen or create a new issue.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono
Projects
None yet
Development

No branches or pull requests

10 participants