<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Sorting TimeZoneInfo.GetSystemTimeZones() properly</title>
	<atom:link href="http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 02:46:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Graham</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-14155</link>
		<dc:creator><![CDATA[Graham]]></dc:creator>
		<pubDate>Fri, 04 Sep 2009 07:34:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-14155</guid>
		<description><![CDATA[Very useful post! There is a line missing from the VB code.  Here is the full working code:

 Public Function GetSensibleSortedTimeZones() As List(Of TimeZoneInfo)

    Dim timeZones As List(Of TimeZoneInfo) = New List(Of TimeZoneInfo)(TimeZoneInfo.GetSystemTimeZones())
    timeZones.Sort(New Comparison(Of TimeZoneInfo)(AddressOf CompareTimeZones))

    Return timeZones

  End Function


  Private Function CompareTimeZones(ByVal left As TimeZoneInfo, ByVal right As TimeZoneInfo) As Integer

    Dim comparison As Integer = left.BaseUtcOffset.CompareTo(right.BaseUtcOffset)
    &#039; If BaseUtcOffset identical then sort by DisplayName as well
    Return IIf(comparison = 0, String.CompareOrdinal(left.DisplayName, right.DisplayName), comparison)

  End Function]]></description>
		<content:encoded><![CDATA[<p>Very useful post! There is a line missing from the VB code.  Here is the full working code:</p>
<p> Public Function GetSensibleSortedTimeZones() As List(Of TimeZoneInfo)</p>
<p>    Dim timeZones As List(Of TimeZoneInfo) = New List(Of TimeZoneInfo)(TimeZoneInfo.GetSystemTimeZones())<br />
    timeZones.Sort(New Comparison(Of TimeZoneInfo)(AddressOf CompareTimeZones))</p>
<p>    Return timeZones</p>
<p>  End Function</p>
<p>  Private Function CompareTimeZones(ByVal left As TimeZoneInfo, ByVal right As TimeZoneInfo) As Integer</p>
<p>    Dim comparison As Integer = left.BaseUtcOffset.CompareTo(right.BaseUtcOffset)<br />
    &#8216; If BaseUtcOffset identical then sort by DisplayName as well<br />
    Return IIf(comparison = 0, String.CompareOrdinal(left.DisplayName, right.DisplayName), comparison)</p>
<p>  End Function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barack Obama</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-13873</link>
		<dc:creator><![CDATA[Barack Obama]]></dc:creator>
		<pubDate>Fri, 12 Jun 2009 02:25:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-13873</guid>
		<description><![CDATA[Another way to do this is to use Linq:

TimeZoneInfo.GetSystemTimeZones().OrderBy(Function(zone As TimeZoneInfo) zone.BaseUtcOffset.TotalHours)]]></description>
		<content:encoded><![CDATA[<p>Another way to do this is to use Linq:</p>
<p>TimeZoneInfo.GetSystemTimeZones().OrderBy(Function(zone As TimeZoneInfo) zone.BaseUtcOffset.TotalHours)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tatham Oddie</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12524</link>
		<dc:creator><![CDATA[Tatham Oddie]]></dc:creator>
		<pubDate>Tue, 12 Feb 2008 03:56:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12524</guid>
		<description><![CDATA[Hi Whitney,

I have updated the post accordingly.

Thanks for your comment!

Tatham]]></description>
		<content:encoded><![CDATA[<p>Hi Whitney,</p>
<p>I have updated the post accordingly.</p>
<p>Thanks for your comment!</p>
<p>Tatham</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Whitney Kew</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12522</link>
		<dc:creator><![CDATA[Whitney Kew]]></dc:creator>
		<pubDate>Sat, 09 Feb 2008 22:43:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12522</guid>
		<description><![CDATA[Unfortunately, it looks like the angle brackets were removed in my last post; of course, List should be List (left angle bracket)TimeZoneInfo(right angle bracket).

:)]]></description>
		<content:encoded><![CDATA[<p>Unfortunately, it looks like the angle brackets were removed in my last post; of course, List should be List (left angle bracket)TimeZoneInfo(right angle bracket).<br />
 <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Whitney Kew</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12521</link>
		<dc:creator><![CDATA[Whitney Kew]]></dc:creator>
		<pubDate>Sat, 09 Feb 2008 22:40:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12521</guid>
		<description><![CDATA[Great find, thanks!  However, the time zone order that I get is not exactly the same as that in the canned Windows time zone dialog box.  By using just the base UTC offset for comparison, I get time zones with the same base UTC offset that aren&#039;t always sorted alphabetically, like they are in the Windows dialog.  For instance, the time zones I get back with a UTC offset of GMT-06:00 are, in this order:

(GMT-06:00) Central Time (US &amp; Canada)
(GMT-06:00) Central America
(GMT-06:00) Saskatchewan
(GMT-06:00) Guadalajara, Mexico City, Monterrey

In the Windows time zone pull-down box, the order is alphabetical:

(GMT-06:00) Central America
(GMT-06:00) Central Time (US &amp; Canada)
(GMT-06:00) Guadalajara, Mexico City, Monterrey
(GMT-06:00) Saskatchewan

So, I added a secondary comparison based on TimeZoneInfo.DisplayName, using String.CompareOrdinal() (from using Reflector to see how .NET does its display name comparison):

List timeZones = new List(TimeZoneInfo.GetSystemTimeZones());
timeZones.Sort(delegate(TimeZoneInfo left, TimeZoneInfo right)
{
   int comparison = left.BaseUtcOffset.CompareTo(right.BaseUtcOffset);
   if (comparison == 0)
   {
      return string.CompareOrdinal(left.DisplayName, right.DisplayName);
   }
   return comparison;
});

This will give you alphabetical sorts for time zones with the same base UTC offset, and your results should match the built-in Windows time zone list exactly.  :)

Whitney Kew]]></description>
		<content:encoded><![CDATA[<p>Great find, thanks!  However, the time zone order that I get is not exactly the same as that in the canned Windows time zone dialog box.  By using just the base UTC offset for comparison, I get time zones with the same base UTC offset that aren&#8217;t always sorted alphabetically, like they are in the Windows dialog.  For instance, the time zones I get back with a UTC offset of GMT-06:00 are, in this order:</p>
<p>(GMT-06:00) Central Time (US &amp; Canada)<br />
(GMT-06:00) Central America<br />
(GMT-06:00) Saskatchewan<br />
(GMT-06:00) Guadalajara, Mexico City, Monterrey</p>
<p>In the Windows time zone pull-down box, the order is alphabetical:</p>
<p>(GMT-06:00) Central America<br />
(GMT-06:00) Central Time (US &amp; Canada)<br />
(GMT-06:00) Guadalajara, Mexico City, Monterrey<br />
(GMT-06:00) Saskatchewan</p>
<p>So, I added a secondary comparison based on TimeZoneInfo.DisplayName, using String.CompareOrdinal() (from using Reflector to see how .NET does its display name comparison):</p>
<p>List timeZones = new List(TimeZoneInfo.GetSystemTimeZones());<br />
timeZones.Sort(delegate(TimeZoneInfo left, TimeZoneInfo right)<br />
{<br />
   int comparison = left.BaseUtcOffset.CompareTo(right.BaseUtcOffset);<br />
   if (comparison == 0)<br />
   {<br />
      return string.CompareOrdinal(left.DisplayName, right.DisplayName);<br />
   }<br />
   return comparison;<br />
});</p>
<p>This will give you alphabetical sorts for time zones with the same base UTC offset, and your results should match the built-in Windows time zone list exactly.  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Whitney Kew</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daniella</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12520</link>
		<dc:creator><![CDATA[daniella]]></dc:creator>
		<pubDate>Tue, 05 Feb 2008 15:20:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12520</guid>
		<description><![CDATA[Hi again! Yesterday You saved me the day!!! ;)]]></description>
		<content:encoded><![CDATA[<p>Hi again! Yesterday You saved me the day!!! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tatham Oddie</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12519</link>
		<dc:creator><![CDATA[Tatham Oddie]]></dc:creator>
		<pubDate>Mon, 04 Feb 2008 23:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12519</guid>
		<description><![CDATA[Hi Daniella,

I have updated the post with a VB.NET version.


Tatham]]></description>
		<content:encoded><![CDATA[<p>Hi Daniella,</p>
<p>I have updated the post with a VB.NET version.</p>
<p>Tatham</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daniella</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12518</link>
		<dc:creator><![CDATA[daniella]]></dc:creator>
		<pubDate>Mon, 04 Feb 2008 23:34:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12518</guid>
		<description><![CDATA[Thanks a lot!! I&#039;ll test it now!! ;)]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot!! I&#8217;ll test it now!! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daniella</title>
		<link>http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12517</link>
		<dc:creator><![CDATA[daniella]]></dc:creator>
		<pubDate>Mon, 04 Feb 2008 21:59:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tatham.oddie.com.au/2007/12/25/sorting-timezoneinfogetsystemtimezones-properly/#comment-12517</guid>
		<description><![CDATA[I have the same problem but I work in VB and I have no matter to trasnlate it to VB... May somebody help me?!]]></description>
		<content:encoded><![CDATA[<p>I have the same problem but I work in VB and I have no matter to trasnlate it to VB&#8230; May somebody help me?!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

