{"id":1251,"date":"2014-11-21T13:32:26","date_gmt":"2014-11-21T18:32:26","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=1251"},"modified":"2019-11-01T11:25:57","modified_gmt":"2019-11-01T15:25:57","slug":"time-zone-terminology","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2014\/11\/21\/time-zone-terminology\/","title":{"rendered":"Time zone terminology"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><p>An email thread about a date-related design question had me thinking about terminology this week. <i>(Note: There's nothing about image processing in today's post. Sorry!)<\/i><\/p><p>Specifically, I was thinking about the term <i>time zone<\/i>. In the U.S. you might see a date written this way:<\/p><p>November 21, 2004 1:02 PM (EST)<\/p><p>EST means <i>Eastern Standard Time<\/i> in the U.S. Or you might see a date written like this:<\/p><p>11\/21\/2004 8:30 (-04:00)<\/p><p>Many people refer to EST or -04:00 as the \"time zone.\" However, because I work across the hall from the chief designer and implementer (Hi, P^2) of the new datetime suite of functions in MATLAB R2014b, I know that these are more properly referred to as <i>time zone offsets<\/i>.<\/p><p>A time zone is a much more complex concept than a simple offset from UTC. For example, a time zone encompasses both current and historical rules for using Daylight Saving Time.<\/p><p>The time zone offset for a given time depends not only on the time zone but also both the year and the day-of-year.<\/p><p>The dependence on the day-of-year is pretty obvious. In the fall season where I live, the time zone offset depends on whether the day is before or after the first Sunday in November.<\/p><pre class=\"codeinput\">d1 = datetime(<span class=\"string\">'October 15, 2014'<\/span>,<span class=\"string\">'TimeZone'<\/span>,<span class=\"string\">'America\/New_York'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nd1 = \r\n\r\n   15-Oct-2014\r\n\r\n<\/pre><pre class=\"codeinput\">tzoffset(d1)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   -4:00\r\n\r\n<\/pre><pre class=\"codeinput\">d2 = datetime(<span class=\"string\">'November 15, 2014'<\/span>,<span class=\"string\">'TimeZone'<\/span>,<span class=\"string\">'America\/New_York'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nd2 = \r\n\r\n   15-Nov-2014\r\n\r\n<\/pre><pre class=\"codeinput\">tzoffset(d2)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   -5:00\r\n\r\n<\/pre><p>Most of the state of Arizona does not observe Daylight Saving Time.<\/p><pre class=\"codeinput\">d3 = datetime(<span class=\"string\">'October 15, 2014'<\/span>,<span class=\"string\">'TimeZone'<\/span>,<span class=\"string\">'America\/Phoenix'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nd3 = \r\n\r\n   15-Oct-2014\r\n\r\n<\/pre><pre class=\"codeinput\">tzoffset(d3)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   -7:00\r\n\r\n<\/pre><pre class=\"codeinput\">d4 = datetime(<span class=\"string\">'November 15, 2014'<\/span>,<span class=\"string\">'TimeZone'<\/span>,<span class=\"string\">'America\/Phoenix'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nd4 = \r\n\r\n   15-Nov-2014\r\n\r\n<\/pre><pre class=\"codeinput\">tzoffset(d4)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   -7:00\r\n\r\n<\/pre><p>The dependence of time zone offset on the year is somewhat less obvious. It turns out that Daylight Saving Time rules change occasionally. In the U.S. the rules were last changed in 2007. Let's compare the time zone offset for noon on Halloween for 2007 and 2006.<\/p><pre class=\"codeinput\">d5 = datetime(<span class=\"string\">'October 31, 2007 12:00 PM'<\/span>,<span class=\"string\">'TimeZone'<\/span>,<span class=\"string\">'America\/New_York'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nd5 = \r\n\r\n   31-Oct-2007 12:00:00\r\n\r\n<\/pre><pre class=\"codeinput\">tzoffset(d5)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   -4:00\r\n\r\n<\/pre><pre class=\"codeinput\">d6 = datetime(<span class=\"string\">'October 31, 2006 12:00 PM'<\/span>,<span class=\"string\">'TimeZone'<\/span>,<span class=\"string\">'America\/New_York'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nd6 = \r\n\r\n   31-Oct-2006 12:00:00\r\n\r\n<\/pre><pre class=\"codeinput\">tzoffset(d6)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   -5:00\r\n\r\n<\/pre><p>Now for just a little fun with MATLAB R2014b date calculations. Most of the U.S. changes from Daylight Saving time to Standard Time at 2:00 AM on the first Sunday of November. Given the year, how can we compute that?<\/p><p>Here's just one way. Start with 2:00 AM on November 1 of the specified year.<\/p><pre class=\"codeinput\">year = 2014;\r\nd = datetime(year,11,1,2,0,0)\r\n<\/pre><pre class=\"codeoutput\">\r\nd = \r\n\r\n   01-Nov-2014 02:00:00\r\n\r\n<\/pre><p>Now use <tt>dateshift<\/tt> to move to the first Sunday.<\/p><pre class=\"codeinput\">dateshift(d,<span class=\"string\">'dayofweek'<\/span>,<span class=\"string\">'Sunday'<\/span>)  <span class=\"comment\">% You can also use 1 instead of 'Sunday'.<\/span>\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   02-Nov-2014 02:00:00\r\n\r\n<\/pre><p>My horoscope for today said \"Your next blog will include an example of an anonymous function for no good reason.\" So here it is. Let's make an anonymous function that returns the exact time for the transition from Daylight Saving Time to Standard time in the U.S.<\/p><pre class=\"codeinput\">f = @(year) dateshift(datetime(year,11,1,2,0,0),<span class=\"string\">'dayofweek'<\/span>,<span class=\"string\">'Sunday'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">\r\nf = \r\n\r\n    @(year)dateshift(datetime(year,11,1,2,0,0),'dayofweek','Sunday')\r\n\r\n<\/pre><pre class=\"codeinput\">f(2014)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   02-Nov-2014 02:00:00\r\n\r\n<\/pre><pre class=\"codeinput\">f(2015)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   01-Nov-2015 02:00:00\r\n\r\n<\/pre><pre class=\"codeinput\">f(2016)\r\n<\/pre><pre class=\"codeoutput\">\r\nans = \r\n\r\n   06-Nov-2016 02:00:00\r\n\r\n<\/pre><p>Of course, this function only works for years between 2007 and whenever the U.S. Congress changes its mind again!<\/p><p>Next week, I promise, I'll get back to writing about image processing. Or maybe colormaps. Unless I write about something else.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_82a1ccf7909144f98df42bb558ba5bd8() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='82a1ccf7909144f98df42bb558ba5bd8 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 82a1ccf7909144f98df42bb558ba5bd8';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_82a1ccf7909144f98df42bb558ba5bd8()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2014b<br><\/p><\/div><!--\r\n82a1ccf7909144f98df42bb558ba5bd8 ##### SOURCE BEGIN #####\r\n%%\r\n% An email thread about a date-related design question had me thinking about\r\n% terminology this week. _(Note: There's nothing about image processing in\r\n% today's post. Sorry!)_\r\n%\r\n% Specifically, I was thinking about the term _time zone_. In the U.S. you might\r\n% see a date written this way:\r\n%\r\n% November 21, 2004 1:02 PM (EST)\r\n%\r\n% EST means _Eastern Standard Time_ in the U.S. Or you might see a date written\r\n% like this:\r\n%\r\n% 11\/21\/2004 8:30 (-04:00)\r\n%\r\n% Many people refer to EST or -04:00 as the \"time zone.\" However, because I work\r\n% across the hall from the chief designer and implementer (Hi, P^2) of the new datetime\r\n% suite of functions in MATLAB R2014b, I know that these are more\r\n% properly referred to as _time zone offsets_.\r\n%\r\n% A time zone is a much more complex concept than a simple offset from UTC. For\r\n% example, a time zone encompasses both current and historical rules for\r\n% using Daylight Saving Time.\r\n%\r\n% The time zone offset for a given time depends not only on the time zone but\r\n% also both the year and the day-of-year.\r\n%\r\n% The dependence on the day-of-year is pretty obvious. In the fall season where\r\n% I live, the time zone offset depends on whether the day is before or after the\r\n% first Sunday in November.\r\n\r\nd1 = datetime('October 15, 2014','TimeZone','America\/New_York')\r\n\r\n%%\r\ntzoffset(d1)\r\n\r\n%%\r\n\r\nd2 = datetime('November 15, 2014','TimeZone','America\/New_York')\r\n\r\n%%\r\ntzoffset(d2)\r\n\r\n%%\r\n% Most of the state of Arizona does not observe Daylight Saving Time.\r\n\r\nd3 = datetime('October 15, 2014','TimeZone','America\/Phoenix')\r\n\r\n%%\r\ntzoffset(d3)\r\n\r\n%%\r\n\r\nd4 = datetime('November 15, 2014','TimeZone','America\/Phoenix')\r\n\r\n%%\r\ntzoffset(d4)\r\n\r\n%%\r\n% The dependence of time zone offset on the year is somewhat less obvious. It\r\n% turns out that Daylight Saving Time rules change occasionally. In the U.S. the\r\n% rules were last changed in 2007. Let's compare the time zone offset for noon\r\n% on Halloween for 2007 and 2006.\r\n\r\nd5 = datetime('October 31, 2007 12:00 PM','TimeZone','America\/New_York')\r\n\r\n%%\r\ntzoffset(d5)\r\n\r\n%%\r\n\r\nd6 = datetime('October 31, 2006 12:00 PM','TimeZone','America\/New_York')\r\n\r\n%%\r\ntzoffset(d6)\r\n\r\n%%\r\n% Now for just a little fun with MATLAB R2014b date calculations. Most of the\r\n% U.S. changes from Daylight Saving time to Standard Time at 2:00 AM on the\r\n% first Sunday of November. Given the year, how can we compute that?\r\n%\r\n% Here's just one way. Start with 2:00 AM on November 1 of the specified year.\r\n\r\nyear = 2014;\r\nd = datetime(year,11,1,2,0,0)\r\n\r\n%%\r\n% Now use |dateshift| to move to the first Sunday.\r\n\r\ndateshift(d,'dayofweek','Sunday')  % You can also use 1 instead of 'Sunday'.\r\n\r\n%%\r\n% My horoscope for today said \"Your next blog will include an example of an\r\n% anonymous function for no good reason.\" So here it is. Let's make an anonymous\r\n% function that returns the exact time for the transition from Daylight Saving\r\n% Time to Standard time in the U.S.\r\n\r\nf = @(year) dateshift(datetime(year,11,1,2,0,0),'dayofweek','Sunday')\r\n\r\n%%\r\nf(2014)\r\n\r\n%%\r\nf(2015)\r\n\r\n%%\r\nf(2016)\r\n\r\n%%\r\n% Of course, this function only works for years between 2007 and whenever the\r\n% U.S. Congress changes its mind again!\r\n%\r\n% Next week, I promise, I'll get back to writing about image processing. Or\r\n% maybe colormaps. Unless I write about something else.\r\n\r\n\r\n##### SOURCE END ##### 82a1ccf7909144f98df42bb558ba5bd8\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nAn email thread about a date-related design question had me thinking about terminology this week. (Note: There's nothing about image processing in today's post. Sorry!)Specifically, I was... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2014\/11\/21\/time-zone-terminology\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[1099,1095,1097],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1251"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=1251"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1251\/revisions"}],"predecessor-version":[{"id":3829,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1251\/revisions\/3829"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=1251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=1251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}