{"id":382,"date":"2009-11-03T21:26:29","date_gmt":"2009-11-04T04:26:29","guid":{"rendered":"http:\/\/www.evardsson.com\/blog\/?p=382"},"modified":"2011-07-17T11:19:58","modified_gmt":"2011-07-17T18:19:58","slug":"daylight-saving-time-headaches","status":"publish","type":"post","link":"https:\/\/www.evardsson.com\/blog\/2009\/11\/03\/daylight-saving-time-headaches\/","title":{"rendered":"Daylight Saving Time Headaches"},"content":{"rendered":"<p>I have never been particularly fond of the concept of Daylight Saving Time (cutting one off of a blanket and sewing to the other end does not make a longer blanket.) This time around, though, I ran into an issue involving the perfect combination of a monthly cron job, a server set to local time and the switch from Daylight Saving to Standard Time on the first of the month.<\/p>\n<p>At precisely 1:14 am on the first day of the month the cron job ran, as it does the first day of every month, and picked a raffle winner for one of our client&#8217;s monthly contests. At 2:00 am the time on the server rolled back to 1:00 am in accordance with the switch to Standard Time for the US. Fourteen minutes later the job ran again, and picked another winner.<\/p>\n<p>Whoops. Now our system has awarded two people a single prize. Telling the second one to get the prize that they didn&#8217;t really win would not get us any points with the client, as their customer would be upset. Likewise, charging the client for the second prize is a non-starter, as it is, in fact, our fault. When I inherited these systems I looked through all the cron jobs to get a feel for what the system is doing and when. What didn&#8217;t occur to me, however, was that jobs scheduled at the wrong time of day could fall victim to Daylight Saving\/Standard Time change-overs.<\/p>\n<p>Any daily job that runs between 1:00 am and 2:00 am will fail to run once a year (Standard -&gt; Daylight Saving when clocks jump ahead an hour) and will run twice once a year (Daylight Saving -&gt; Standard Time when clocks fall back from 2:00 am to 1:00 am). Weekly jobs that run between 1:00 am and 2:00 am on Sundays will likewise misbehave, while monthly jobs, regardless of day of the month, have a small chance of experiencing one of these issues. In this case, the job runs on the 1st, which happened to be the first Sunday in November, and bang: error.<\/p>\n<p>Needless to say, we modified all the cron jobs to ensure than none of them start between 1:00 am and 2:00 am.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have never been particularly fond of the concept of Daylight Saving Time (cutting one off of a blanket and sewing to the other end does not make a longer blanket.) This time around, though, &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[40],"tags":[177,156,102],"class_list":["post-382","post","type-post","status-publish","format-standard","hentry","category-best-practices","tag-best-practices","tag-linux","tag-sysadmin"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pxT7i-6a","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/comments?post=382"}],"version-history":[{"count":2,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}