{"id":11,"date":"2010-03-13T13:14:13","date_gmt":"2010-03-13T21:14:13","guid":{"rendered":"http:\/\/blog.jbrowne.com\/?p=11"},"modified":"2010-03-13T13:14:13","modified_gmt":"2010-03-13T21:14:13","slug":"the-united-states-is-not-mexico","status":"publish","type":"post","link":"https:\/\/blog.jbrowne.com\/?p=11","title":{"rendered":"The United States is not Mexico"},"content":{"rendered":"<p><strong>The Problem Report<\/strong><\/p>\n<p>A programmer I support sent me the following last October:<\/p>\n<blockquote><p>Hey Jim,<\/p>\n<p>I just found a difference between our windows and unix boxes regarding time that is standing in the way of me finishing [&#8230;] I&#8217;ve been working on and wanted your help.<\/p>\n<p>[Description of test code and environment]<\/p>\n<p>This is Test.java taking a milliseconds since the epoch time: 1256975836665 and turning that into a date.\u00a0 It should give 2009-10-31 00:57:16 but is off by one hour and does if you run the same from a windows box on our network.<\/p>\n<p>I don&#8217;t know how to do the same from the command line to see if it&#8217;s java specific or machine specific, but was wondering if you could look at those machines and see if perhaps timezone or daylight saving is set incorrectly?<\/p><\/blockquote>\n<p><strong>The Investigation<\/strong><\/p>\n<p>Honestly, it had been a long time since I looked at the time zone configuration on a Linux box.\u00a0 I had helped build out <a href=\"http:\/\/www.cnet.com\">CNET<\/a>&#8216;s Kickstart infrastructure in 2002 and hadn&#8217;t really looked at system settings like time zone since.\u00a0 Upgrading the zoneinfo database to deal with changes was just an RPM upgrade and never required much thought.\u00a0 So, I had to refresh my knowledge.\u00a0 Further, all of the systems I support for <a href=\"http:\/\/www.42lines.net\">42Lines<\/a> and our clients I inherited in mid-January, so I didn&#8217;t know how they were set up.<\/p>\n<p>The key file here is <strong>\/etc\/localtime<\/strong>.\u00a0 What I found surprising was that instead of a symlink to the correct file in <strong>\/usr\/share\/zoneinfo\/<\/strong>, it was just a file.\u00a0 This is a problem as the zoneinfo data for a zone is a compiled binary format and not human readable.\u00a0 So, how to determine what zone it was?\u00a0 In cases like this I turn to my trusty friend <strong>md5sum<\/strong>.<\/p>\n<pre># md5sum \/etc\/localtime\r\nf3e91959e492f62136812f8f556713a3\u00a0 \/etc\/localtime\r\n# find \/usr\/share\/zoneinfo\/America -type f | xargs md5sum | grep f3e91959e492f62136812f8f556713a3\r\nf3e91959e492f62136812f8f556713a3\u00a0 \/usr\/share\/zoneinfo\/America\/Ensenada\r\nf3e91959e492f62136812f8f556713a3\u00a0 \/usr\/share\/zoneinfo\/America\/Tijuana<\/pre>\n<p>Okay, so the timezone is set to Tijuana.\u00a0 Tijuana is in the Pacific Timezone just like San Francisco, right?\u00a0 <strong>Sometimes<\/strong>.<\/p>\n<p>I\u00a0 had to coordinate a massive update at <a href=\"http:\/\/www.cnet.com\/\">CNET<\/a> in 2007 thanks to Congress <a href=\"http:\/\/en.wikipedia.org\/wiki\/Energy_Policy_Act_of_2005\">changing<\/a> the DST rules for the United States.\u00a0 So I suspected that that the problem might be due to the new rules starting in 2007.\u00a0 I wasn&#8217;t working with these systems during the last DST transition, so it is possible that they just had an old <a href=\"http:\/\/en.wikipedia.org\/wiki\/Tz_database\">zoneinfo database<\/a> that didn&#8217;t include the recent rule changes.<\/p>\n<p>I checked the version of tzdata (rpm -qf \/usr\/share\/zoneinfo\/America\/Tijuana) and the version post-dated that 2007 changes (tzdata-2009u-1).\u00a0 So, perhaps Mexico didn&#8217;t implement the same changes to DST that the United States and Canada did?\u00a0 Again, the zoneinfo database is binary and somewhat to my surprise the RPMs do not install the source.\u00a0 So, I hunted down the <a href=\"ftp:\/\/elsie.nci.nih.gov\/pub\/\">source<\/a> and took a look.<\/p>\n<p>It turns out the Mexico has had a pretty turbulent relationship with DST, far more so than the US.\u00a0 The comments in the zoneinfo source file reflect not only the difficulty in following such things, but the dedication of a few select people to try and translate political intent and law into something logical (a rough task regardless of country.)\u00a0 Here&#8217;s what Mexico was using starting in 2002:<\/p>\n<pre>Rule\u00a0\u00a0\u00a0 Mexico\u00a0 2002\u00a0\u00a0\u00a0 max\u00a0\u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Apr\u00a0\u00a0\u00a0\u00a0 Sun&gt;=1\u00a0 2:00\u00a0\u00a0\u00a0 1:00\u00a0\u00a0\u00a0 D\r\nRule\u00a0\u00a0\u00a0 Mexico\u00a0 2002\u00a0\u00a0\u00a0 max\u00a0\u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Oct\u00a0\u00a0\u00a0\u00a0 lastSun 2:00\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S<\/pre>\n<p>So as soon as the US changed in 2007 to:<\/p>\n<pre>Rule\u00a0\u00a0\u00a0 US\u00a0\u00a0\u00a0\u00a0\u00a0 2007\u00a0\u00a0\u00a0 max\u00a0\u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Mar\u00a0\u00a0\u00a0\u00a0 Sun&gt;=8\u00a0 2:00\u00a0\u00a0\u00a0 1:00\u00a0\u00a0\u00a0 D\r\nRule\u00a0\u00a0\u00a0 US\u00a0\u00a0\u00a0\u00a0\u00a0 2007\u00a0\u00a0\u00a0 max\u00a0\u00a0\u00a0\u00a0 -\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Nov\u00a0\u00a0\u00a0\u00a0 Sun&gt;=1\u00a0 2:00\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S<\/pre>\n<p>Anyone in the United States using Tijuana as their zone had the wrong time during DST.\u00a0 It turns out that the border cities in Mexico will change to US rules in 2010.<\/p>\n<p>My response to the programmer:<\/p>\n<blockquote><p>This is because the TZ on that machine is set to America\/Tijuana instead of US\/Pacific and the US (but not Mexico) changed the DST rules starting for 2007.\u00a0 10\/30 falls in the window between the old DST ending date (last Sunday in Oct) and the current ending date (first Sun in Nov) for the US.\u00a0 Thanks, Congress.<\/p><\/blockquote>\n<p>Another programmer chimed in with the witty comment:<\/p>\n<blockquote><p>Those machines are not allowed to be in Tijuana according to our health care plan.\u00a0 If their drives crash, they won&#8217;t be covered.<\/p><\/blockquote>\n<p><strong>The Solution<\/strong><\/p>\n<p>Ensure your time zone is set correctly.\u00a0 We changed to US\/Pacific.\u00a0 I also ensured that \/etc\/localtime was a symlink to the appropriate zoneinfo file to make things a bit more obvious.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Problem Report A programmer I support sent me the following last October: Hey Jim, I just found a difference between our windows and unix boxes regarding time that is standing in the way of me finishing [&#8230;] I&#8217;ve been working on and wanted your help. [Description of test code and environment] This is Test.java [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[10,8,9],"_links":{"self":[{"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=\/wp\/v2\/posts\/11"}],"collection":[{"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11"}],"version-history":[{"count":5,"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":16,"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions\/16"}],"wp:attachment":[{"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jbrowne.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}