CodeSOD: All the Time in the World

Time zones are hard. And, to my surprise, if you want to enumerate all the time zones in the world in C#, there isn't an easy way to do that. You can enumerate all the time zones configured on the host computer (in Windows), but that may be incomplete and also may use idiosyncratic names, since it doesn't use the IANA database of timezones.

This leaves developers with a three real options. The first would be to either load the IANA database yourself, and the second would be to use a library that provides it.

Which, Louis's team did the first- they maintained a time zone database in their application database that contained all the time zones, in their canonical names.

Or, I should say, most of Louis's team did the first. One developer found the third option. They didn't use the database. They didn't use a library. They just hard-coded all the options into the UI:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="Controls_User_Edit_EmployeeEditTimeZone"
    CodeBehind="EmployeeEditTimeZone.ascx.cs" %>
<asp:DropDownList runat="server" ID="lstTimeZones">
    <asp:ListItem Text="(GMT) Casablanca, Monrovia" />
    <asp:ListItem Text="(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London" />
    <asp:ListItem Text="(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna" />
    <asp:ListItem Text="(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague" />
    <asp:ListItem Text="(GMT+01:00) Brussels, Copenhagen, Madrid, Paris" />
    <asp:ListItem Text="(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb" />
    <asp:ListItem Text="(GMT+01:00) West Central Africa" />
    <asp:ListItem Text="(GMT+02:00) Athens, Beirut, Istanbul, Minsk" />
    <asp:ListItem Text="(GMT+02:00) Bucharest" />
    <asp:ListItem Text="(GMT+02:00) Cairo" />
    <asp:ListItem Text="(GMT+02:00) Harare, Pretoria" />
    <asp:ListItem Text="(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius" />
    <asp:ListItem Text="(GMT+02:00) Jerusalem" />
    <asp:ListItem Text="(GMT+03:00) Baghdad" />
    <asp:ListItem Text="(GMT+03:00) Kuwait, Riyadh" />
    <asp:ListItem Text="(GMT+03:00) Moscow, St. Petersburg, Volgograd" />
    <asp:ListItem Text="(GMT+03:00) Nairobi" />
    <asp:ListItem Text="(GMT+03:30) Tehran" />
    <asp:ListItem Text="(GMT+04:00) Abu Dhabi, Muscat" />
    <asp:ListItem Text="(GMT+04:00) Baku, Tbilisi, Yerevan" />
    <asp:ListItem Text="(GMT+04:30) Kabul" />
    <asp:ListItem Text="(GMT+05:00) Ekaterinburg" />
    <asp:ListItem Text="(GMT+05:00) Islamabad, Karachi, Tashkent" />
    <asp:ListItem Text="(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi" />
    <asp:ListItem Text="(GMT+05:45) Kathmandu" />
    <asp:ListItem Text="(GMT+06:00) Almaty, Novosibirsk" />
    <asp:ListItem Text="(GMT+06:00) Astana, Dhaka" />
    <asp:ListItem Text="(GMT+06:00) Sri Jayawardenepura" />
    <asp:ListItem Text="(GMT+06:30) Rangoon" />
    <asp:ListItem Text="(GMT+07:00) Bangkok, Hanoi, Jakarta" />
    <asp:ListItem Text="(GMT+07:00) Krasnoyarsk" />
    <asp:ListItem Text="(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi" />
    <asp:ListItem Text="(GMT+08:00) Irkutsk, Ulaan Bataar" />
    <asp:ListItem Text="(GMT+08:00) Kuala Lumpur, Singapore" />
    <asp:ListItem Text="(GMT+08:00) Perth" />
    <asp:ListItem Text="(GMT+08:00) Taipei" />
    <asp:ListItem Text="(GMT+09:00) Osaka, Sapporo, Tokyo" />
    <asp:ListItem Text="(GMT+09:00) Seoul" />
    <asp:ListItem Text="(GMT+09:00) Yakutsk" />
    <asp:ListItem Text="(GMT+09:30) Adelaide" />
    <asp:ListItem Text="(GMT+09:30) Darwin" />
    <asp:ListItem Text="(GMT+10:00) Brisbane" />
    <asp:ListItem Text="(GMT+10:00) Canberra, Melbourne, Sydney" />
    <asp:ListItem Text="(GMT+10:00) Guam, Port Moresby" />
    <asp:ListItem Text="(GMT+10:00) Hobart" />
    <asp:ListItem Text="(GMT+10:00) Vladivostok" />
    <asp:ListItem Text="(GMT+11:00) Magadan, Solomon Is., New Caledonia" />
    <asp:ListItem Text="(GMT+12:00) Auckland, Wellington" />
    <asp:ListItem Text="(GMT+12:00) Fiji, Kamchatka, Marshall Is." />
    <asp:ListItem Text="(GMT+13:00) Nuku'alofa" />
    <asp:ListItem Text="(GMT-01:00) Azores" />
    <asp:ListItem Text="(GMT-01:00) Cape Verde Is." />
    <asp:ListItem Text="(GMT-02:00) Mid-Atlantic" />
    <asp:ListItem Text="(GMT-03:00) Brasilia" />
    <asp:ListItem Text="(GMT-03:00) Buenos Aires, Georgetown" />
    <asp:ListItem Text="(GMT-03:00) Greenland" />
    <asp:ListItem Text="(GMT-03:30) Newfoundland" />
    <asp:ListItem Text="(GMT-04:00) Atlantic Time (Canada)" />
    <asp:ListItem Text="(GMT-04:00) Caracas, La Paz" />
    <asp:ListItem Text="(GMT-04:00) Santiago" />
    <asp:ListItem Text="(GMT-05:00) Bogota, Lima, Quito" />
    <asp:ListItem Text="(GMT-05:00) Eastern Time (US & Canada)" />
    <asp:ListItem Text="(GMT-05:00) Indiana (East)" />
    <asp:ListItem Text="(GMT-06:00) Central America" />
    <asp:ListItem Text="(GMT-06:00) Central Time (US & Canada)" />
    <asp:ListItem Text="(GMT-06:00) Guadalajara, Mexico City, Monterrey" />
    <asp:ListItem Text="(GMT-06:00) Saskatchewan" />
    <asp:ListItem Text="(GMT-07:00) Arizona" />
    <asp:ListItem Text="(GMT-07:00) Chihuahua, La Paz, Mazatlan" />
    <asp:ListItem Text="(GMT-07:00) Mountain Time (US & Canada)" />
    <asp:ListItem Text="(GMT-08:00) Pacific Time (US & Canada); Tijuana" />
    <asp:ListItem Text="(GMT-09:00) Alaska" />
    <asp:ListItem Text="(GMT-10:00) Hawaii" />
    <asp:ListItem Text="(GMT-11:00) Midway Island, Samoa" />
    <asp:ListItem Text="(GMT-12:00) International Date Line West" />
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published. Required fields are marked *