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

WinRT: ITimeZoneEx.ConvertTime cause an exception with certain timezones and years #9

Open
pnp0a03 opened this issue Jan 5, 2017 · 4 comments

Comments

@pnp0a03
Copy link

pnp0a03 commented Jan 5, 2017

I found that ... with Win10 UWP, ITimeZoneEx.ConvertTime cause exception with some certain timezones and years. This issue does not occur with Desktop app.

I've wrote the small test code as below.`

        string strout = "";
        var allZones = TimeZoneService.AllTimeZones;

        foreach (var zone in allZones)
        {
            string thisTzError = "";
            int year = 1901;
            int yearMax = 2099;
            var tz = TimeZoneService.FindSystemTimeZoneById(zone.Id);

            while (year < yearMax)
            {
                DateTimeOffset timeOffset = new DateTimeOffset(new DateTime(year, 4, 1));
                try
                {
                    tz.ConvertTime(timeOffset);
                }
                catch (Exception ex)
                {
                    thisTzError = thisTzError + timeOffset.ToString("yyyy") + " ";
                }

                year = year + 1;
            }

            if (!string.IsNullOrEmpty(thisTzError))
            {
                strout = strout + zone.Id + ", " + thisTzError + "\n";
            }
        }`

If you run the code at UWP app, the result is following. If the app is WinForms desktop, nothing happen.

Central Brazilian Standard Time, 2007
Chatham Islands Standard Time, 2017 2023 2028 2034 2045 2051 2056 2062 2073 2079 2084 2090
E. South America Standard Time, 2007
Egypt Standard Time, 1903 1908 1914 1925 1931 1936 1942 1953 1959 1964 1970 1981 1987 1992 1998 2008
Magadan Standard Time, 2016
Mid-Atlantic Standard Time, 1905 1911 1916 1922 1933 1939 1944 1950 1961 1967 1972 1978 1989 1995 2000 2006 2017 2023 2028 2034 2045 2051 2056 2062 2073 2079 2084 2090
New Zealand Standard Time, 2017 2023 2028 2034 2045 2051 2056 2062 2073 2079 2084 2090
Samoa Standard Time, 2017 2023 2028 2034 2045 2051 2056 2062 2073 2079 2084 2090
Syria Standard Time, 1903 1908 1914 1925 1931 1936 1942 1953 1959 1964 1970 1981 1987 1992 1998
Ulaanbaatar Standard Time, 2021 2027 2032 2038 2049 2055 2060 2066 2077 2083 2088 2094
W. Mongolia Standard Time, 1904 1910 1921 1927 1932 1938 1949 1955 1960 1966 1977 1983 1988 1994 2005 2021 2027 2032 2038 2049 2055 2060 2066 2077 2083 2088 2094

I've tried to debug it, and I could identify the point but I have no idea to solve it.
It seems that... the method IsDaylightTime call the method FindTimeZoneData ( line 153 at TimeZones.WinRT.Shared/Internal/TimeZoneInfoEx.cs ).
At the error case, this method - FindTimeZoneData - generate the invalid date like as 31-Feb or 31-Sept. This invalid data cause the exception at the end of this method.

@calbot
Copy link

calbot commented Aug 10, 2017

I have the same problem. Did you find a solution?

@pnp0a03
Copy link
Author

pnp0a03 commented Aug 10, 2017

@calbot , No. My project that use this package is old one, maintenance mode. So I've put an exception handler and have apologized for users. 😢
If I have a chance, I'll rewrite my code to use the NodaTime.

@clairernovotny
Copy link
Collaborator

I would suggest moving to the built-in TimeZoneInfo class for this. It's available on the platforms now, so this library doesn't need to exist anymore.

@calbot
Copy link

calbot commented Aug 10, 2017

TimeZoneInfo doesn't seem to support looking up TimeZoneInfo's by ID though. Is that something from "UWP"?

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