{"id":35619,"date":"2018-01-22T03:01:18","date_gmt":"2018-01-21T17:01:18","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=35619"},"modified":"2018-01-21T14:32:09","modified_gmt":"2018-01-21T04:32:09","slug":"php-sun-information-timezone-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-sun-information-timezone-tutorial\/","title":{"rendered":"PHP Sun Information TimeZone Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Sun Information TimeZone Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information_timezone.jpg\" title=\"PHP Sun Information TimeZone Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP Sun Information TimeZone Tutorial<\/p><\/div>\n<p>What links time and place? &#8230; Give up?<\/p>\n<p>What links time and place when you are programming, a lot? &#8230; Give up?<\/p>\n<p>What links time and place when you are PHP programming, heaps? &#8230; Give up?<\/p>\n<p>TimeZones &#8230; and PHP is soooooooo good at it in terms of its <a target=_blank title='DateTimeZone class' href='http:\/\/php.net\/manual\/en\/class.datetimezone.php'>DateTimeZone<\/a> class.  So it seems logical that to involve TimeZones in (amongst the logic of) our recent <a title='PHP Sun Information Primer Tutorial' href='#phpsipt'>PHP Sun Information Primer Tutorial<\/a> could help it.  My oath it can!  <font size=1>Don&#8217;t worry, I&#8217;ve told off the fourth finger of my left hand to stop using the word &#8216;can&#8217;.<\/font><\/p>\n<p>Its immediately apparent &#8220;weakness&#8221; is that it presents the time of sunset and sunrise in Greenwich Mean Time (GMT), back then the way to go, because we hadn&#8217;t thought to use TimeZones in any meaningful way.  To use TimeZones in a meaningful way could mean (at least) one of <i>two<\/i> things &#8230;<\/p>\n<ul>\n<li>the timezone at the web server (where the URL you got to &#8220;surfing the net&#8221; bases its time on) &#8230; or &#8230; spoiler alert &#8230; today&#8217;s much more relevant &#8230;<\/li>\n<li>client timezone being the timezone of the place where the user is located with their computing device<\/li>\n<\/ul>\n<p>To try to help the user out here, then, you can&#8217;t use anything PHP, which is a serverside language, to determine, programmatically, what is a (good guess regarding what is a) user&#8217;s default timezone.  In times past we don&#8217;t think we&#8217;ve stumbled upon the Javascript &#8230;<\/p>\n<p><code><br \/>\n    var tzis='' + <a target=_blank title='https:\/\/www.ecma-international.org\/ecma-402\/#sec-intl.datetimeformat' href='https:\/\/www.ecma-international.org\/ecma-402\/#sec-intl.datetimeformat'>Intl.DateTimeFormat()<\/a>.resolvedOptions().timeZone;   \/\/ Thanks to <a target=_blank title='Thanks to https:\/\/stackoverflow.com\/questions\/22618056\/javascript-timezone-information-how-to-get-america-los-angeles-or-equivalent\/22625076#22625076' href='https:\/\/stackoverflow.com\/questions\/22618056\/javascript-timezone-information-how-to-get-america-los-angeles-or-equivalent\/22625076#22625076'>https:\/\/stackoverflow.com\/questions\/22618056\/javascript-timezone-information-how-to-get-america-los-angeles-or-equivalent\/22625076#22625076<\/a><br \/>\n    if (tzis != '') document.getElementById('timezone').value=tzis;<br \/>\n<\/code><\/p>\n<p> &#8230; that we now add up the top of this PHP program&#8217;s <i>onload<\/i> <i>ol()<\/i> Javascript function, so that the serverside passes the batton onto the clientside, for <a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=cueulBxn1Fw'>help<\/a> setting a (probably more apt than GMT) default timezone to use as the basis for showing sunrise and setset (and other sun information) times relevant to a particular geographical location.  The HTML form &#8230;<\/p>\n<ul>\n<li>method=POST<\/li>\n<li>action=.\/sun_information.php<\/li>\n<\/ul>\n<p> &#8230; completes the circle of all sides of the (client\/server) equation knowing what is a good timezone on which to base your displayed time information.<\/p>\n<p>The <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php\" title=\"Click picture\">live run<\/a> link now uses this PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php-GETME\" title=\"sun_information.php\">sun_information.php<\/a> source code that changed in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php-GETME\" title=\"sun_information.php\">this way<\/a> to facilitate that improvement.<\/p>\n<hr>\n<p id='phpsipt'>Previous relevant <a target=_blank title='PHP Sun Information Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/php-sun-information-primer-tutorial\/'>PHP Sun Information Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Sun Information Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.jpg\" title=\"PHP Sun Information Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP Sun Information Primer Tutorial<\/p><\/div>\n<p>PHP has some great code features built into versions as early as PHP 4, even earlier perhaps, though today&#8217;s work needs PHP 5.  Today, we&#8217;ve built a pretty simple web application around PHP&#8217;s <a target=_blank title='PHP Sun Information' href='http:\/\/php.net\/manual\/en\/function.date-sun-info.php'>date\/time sun information<\/a> function &#8230;<\/p>\n<blockquote cite='http:\/\/php.net\/manual\/en\/function.date-sun-info.php'><p>\ndate_sun_info<br \/>\n<br \/>\n(PHP 5 >= 5.1.2, PHP 7)<br \/>\n<br \/>\ndate_sun_info \u2014 Returns an array with information about sunset\/sunrise and twilight begin\/end\n<\/p><\/blockquote>\n<p>It&#8217;s here at this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php\" title=\"Click picture\">live run<\/a> link that uses the PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php_GETME\" title=\"sun_information.php\">sun_information.php<\/a> source code you can download, and try yourself, if you like.  Within this code we allow, if access permits the user&#8217;s current location be reflected in default latitude and longitude HTML form values via Javascript <a target=_blank title='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Geolocation\/getCurrentPosition' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Geolocation\/getCurrentPosition'>navigator.geolocation.getCurrentPosition(success[, error[, options]])<\/a> call.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d35561' onclick='var dv=document.getElementById(\"d35561\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/php\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d35561' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d35619' onclick='var dv=document.getElementById(\"d35619\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/timezone\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d35619' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>What links time and place? &#8230; Give up? What links time and place when you are programming, a lot? &#8230; Give up? What links time and place when you are PHP programming, heaps? &#8230; Give up? TimeZones &#8230; and PHP &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-sun-information-timezone-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[212,213,301,302,2446,481,483,652,684,719,932,997,1122,2445,1279,1693,1319],"class_list":["post-35619","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-client","tag-clientserver","tag-date","tag-datetime","tag-ecma","tag-geographicals","tag-geolocation","tag-javascript","tag-latitude","tag-longitude","tag-php","tag-programming","tag-server","tag-sun","tag-time","tag-timezone","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35619"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=35619"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35619\/revisions"}],"predecessor-version":[{"id":35622,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35619\/revisions\/35622"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=35619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=35619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=35619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}