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

ToTimeZone throws error on Linux #2

Open
chrisg32 opened this issue Apr 5, 2023 · 1 comment
Open

ToTimeZone throws error on Linux #2

chrisg32 opened this issue Apr 5, 2023 · 1 comment
Labels

Comments

@chrisg32
Copy link
Owner

chrisg32 commented Apr 5, 2023

It appears that the DateTime.ToTimeZone extension method will error on Linux systems because TimeZoneInfo.GetSystemTimeZones() which is used in the implementation returns more than once value and the implementation is expecting one or none (SingleOrDefault).

Timezone string: Central Standard Time
OS: ubuntu-latest

@chrisg32 chrisg32 added the bug label Apr 5, 2023
@chrisg32
Copy link
Owner Author

chrisg32 commented Apr 5, 2023

Probably should have the following implementation:

public abstract class TimeZoneLocator
    {
        public static TimeZoneLocator Default { get; set; } = new SystemTimeZoneLocator();
        public abstract TimeZoneInfo FindTimeZoneById(string timezone);
    }

    public sealed class SystemTimeZoneLocator : TimeZoneLocator
    {
        public override TimeZoneInfo FindTimeZoneById(string timezone)
        {
            return TimeZoneInfo.FindSystemTimeZoneById(timezone);
        }
    }

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

No branches or pull requests

1 participant