{"id":93113,"date":"2016-03-04T07:00:00","date_gmt":"2016-03-04T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=93113"},"modified":"2019-03-13T10:31:11","modified_gmt":"2019-03-13T17:31:11","slug":"20160304-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160304-00\/?p=93113","title":{"rendered":"Why not auto convert week-based time zone information to date-based?"},"content":{"rendered":"<p>When I described the two ways that the <code>TIME_ZONE_INFORMATION<\/code> structure represents the rules for daylight saving time, commenter Voo <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/03\/11\/10139574.aspx#10140261\">argued<\/a> (and I hope I interpreted the message correctly) that either there should be two functions, one for each of the ways, or have <code>Get&shy;Time&shy;Zone&shy;Information&shy;For&shy;Year<\/code> function calculate the day automatically from the week and return that. That way, callers always see the correct day. <\/p>\n<p>Okay, there are multiple things in play here, but they all boil down to &#8220;no code is an island&#8221;. <\/p>\n<p>If all you needed to support was a way to answer the question &#8220;When does daylight saving time start and end in this specific year&#8221;, then certainly the <var>n<\/var>th week rules could be interpreted by the <code>Get&shy;Time&shy;Zone&shy;Information&shy;For&shy;Year<\/code> function, so that all that came out of the function was a specific date and time. <\/p>\n<p>But that&#8217;s not the only function that deals with time zone information. For starters, we have <code>Get&shy;Time&shy;Zone&shy;Information<\/code>. Since this function is not dependent on the year, it wouldn&#8217;t know what year to use to calculate the date on which the third Sunday falls. It would have to leave the structure in generic form. <\/p>\n<p>Now, maybe you say, &#8220;Yeah, these two functions return the same structure, and you just have to know that one of the functions will autoconvert and the other won&#8217;t.&#8221; Some people will find that confusing. <\/p>\n<p>Maybe you solve that problem by saying, &#8220;These two functions return different structures, reflecting their different natures.&#8221; Some people will be frustrated by that, because they will have to write two versions of the same function, one for each structure. <\/p>\n<p>(I&#8217;m not event going to bother adding <code>Get&shy;Dynamic&shy;Time&shy;Zone&shy;Information<\/code>. to the mix.) <\/p>\n<p>And then there&#8217;s the question of whether it&#8217;s okay that the <code>Get<\/code> function returns a structure that cannot be passed into the corresponding <code>Set<\/code> function. (Which is a bit of a pointless question here, seeing as there is no <code>Set&shy;Time&shy;Zone&shy;Information&shy;For&shy;Year<\/code> function, but maybe someday it will show up.) It also means that you cannot compare two <code>TIME_ZONE_INFORMATION<\/code> structures from different years to see whether the time zone transition rules are the same in those years. (This is, admitted, a fringe scenario.) <\/p>\n<p>Two functions seems the less crazy way out. There would be a <code>Get&shy;Unexpanded&shy;Time&shy;Zone&shy;Information&shy;For&shy;Year<\/code> which returns the unprocesed information and a <code>Get&shy;Expanded&shy;Time&shy;Zone&shy;Information&shy;For&shy;Year<\/code> that does the date lookup for the appropriate year. Though personally, I would keep <code>Get&shy;Time&shy;Zone&shy;Information&shy;For&shy;Year<\/code> as-is and add a <code>Calculate&shy;Daylight&shy;Saving&shy;Transition&shy;Dates&shy;For&shy;Year<\/code> function. That way, you could use it to expand other things. <\/p>\n<p>I suspect no such <code>Calculate&shy;Daylight&shy;Saving&shy;Transition&shy;Dates&shy;For&shy;Year<\/code> function exists because the kernel folks have a general bias against writing functions that you could have written yourself, so that they can focus on writing functions that you <i>can&#8217;t<\/i> write yourself because it requires special access to things that only the kernel has access to. (Like querying the current time zone.)  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>What an adorable snowflake.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-93113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>What an adorable snowflake.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=93113"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93113\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=93113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=93113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=93113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}