mattjohnsonpint / TimeZoneNames

Provides a complete source of localized time zone names and abbreviations.
MIT License
199 stars 32 forks source link

WindowsToIanaLookup #3

Closed GusSand closed 9 years ago

GusSand commented 9 years ago

I have a requirement where my server expects Iana Timezones and Windows Phone (in this case) has the Windows TimezoneInfo name. I tried making the ConvertWindowsToIana public, but that doesn't work. I want this to work even in non enlish languages. I believe this library should already have all the date to do the lookup, but it only seems to work in English. Here are a couple of tests I have:

    [Fact]
    public void Can_Get_Iana_Names_For_EN_Eastern()
    {
        const string olsonString = "Eastern Standard Time";
        var names = TimeZoneNames.GetIanaFromWindows(olsonString);
        Assert.Equal("America/New_York", names);
    }

The one above passes. Note that I had changed the name of ConvertWindowsToIana to GetIanaFromWindows to make it consistent.

However if I have the spanish version, it fails:

    [Fact]
    public void Can_Get_Iana_For_SP_Pacific()
    {
        const string olsonString = "hora del Pacífico";

        var names = TimeZoneNames.GetIanaFromWindows(olsonString);
        Assert.Equal("America/Los_Angeles", names);
    }

same thing in french. Any suggestions ?

thanks G

mattjohnsonpint commented 9 years ago

In general, the conversion only works with IDs, which should always be in English. The names that are output can be localized by language, but I wouldn't recommend going the other direction. There are too many ambiguities.

As an example, consider that "Central European Time", is the English display name of many zones, including Europe/Paris, Europe/Stockholm, and others.

The Windows TimeZoneInfo.Id and TimeZoneInfo.StandardName sometimes line up, but they are not the same thing.

If memory serves me correctly Id might not be available on Windows Phone. (I know it wasn't in Silverlight).

You might consider using Noda Time on your Windows Phone app, since it's portable.