{"id":35675,"date":"2018-01-25T03:01:16","date_gmt":"2018-01-24T17:01:16","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=35675"},"modified":"2018-01-24T20:32:52","modified_gmt":"2018-01-24T10:32:52","slug":"php-sun-information-software-integration-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-sun-information-software-integration-tutorial\/","title":{"rendered":"PHP Sun Information Software Integration Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/SunAngle\/sun_angle_now_at.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Sun Information Software Integration Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information_integration.jpg\" title=\"PHP Sun Information Software Integration Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP Sun Information Software Integration Tutorial<\/p><\/div>\n<p>We left off the project of <a title='PHP Sun Information TimeZone Tutorial' href='#phpsitzt'>PHP Sun Information TimeZone Tutorial<\/a> recently adding in that fourth (time) dimension link via the use of TimeZones, and today, that &#8230;<\/p>\n<ul>\n<li>Sun Information is integrated into &#8230;<\/li>\n<li>Sun Angle project<\/li>\n<\/ul>\n<p> &#8230; and vice versa making a &#8220;win win&#8221; scenario, we hope, for both.<\/p>\n<p>The PHP <a target=_blank title='PHP Sun Information' href='http:\/\/php.net\/manual\/en\/function.date-sun-info.php'>date\/time sun information<\/a> method we use does not calculate a sun elevation (&#913;) at &#8220;noon&#8221; exactly, but we are going to settle for this as a sun elevation at the transit point, and if you read (the very helpful) <a target=_blank title='Useful link' href='http:\/\/www.pveducation.org\/pvcdrom\/properties-of-sunlight\/elevation-angle'>link<\/a> (thanks) &#8230;<\/p>\n<blockquote cite='http:\/\/www.pveducation.org\/pvcdrom\/properties-of-sunlight\/elevation-angle'>\n<h1>&#913; = 90 + &#920; &#8211; &#916;<\/h1>\n<p>\nWhen the equation above gives a number greater than 90&deg; then substract the result from 180&deg;. It means the sun at solar noon is coming from the south as is typical the northern hemisphere.<br \/>\n<br \/>\nwhere:<br \/>\n&#920; is the latitude of the location of interest (+ve for the northern hemisphere and -ve for the southern hemisphere).<br \/>\n&#916; is the declination angle, which depends on the day of the year.\n<\/p><\/blockquote>\n<p> &#8230; you may be happy with all but that &#8220;sun declination&#8221; idea above, if you are anything like me?!  You&#8217;ll read that almanacs can be used to calculate these, but we got to see this <a target=_blank title='Great link' href='https:\/\/sciencing.com\/calculate-suns-declination-6904335.html'>great link<\/a>&#8216;s &#8230;<\/p>\n<blockquote cite='https:\/\/sciencing.com\/calculate-suns-declination-6904335.html'><p>\nDetermine how many days have passed since January 1st. For example, the number of days between January 1st and February 14th is 44.<br \/>\n<br \/>\nAdd ten to the number of days passed. Write this number down. Following the example, adding 10 to 44 gives 54.<br \/>\n<br \/>\nDivide 360 by the number of days in the year. Every year has 365 days except leap years. Write this number down. From the example, 360 divided by 365 = 0.9863.<br \/>\n<br \/>\nMultiply the number from Step 2 (the approximate number of days that have passed since the winter solstice) by the amount from Step 3 (the degree of rotation per day). Write down the result. From the example, 54 times .9863 equals 53.2603.<br \/>\n<br \/>\nFind the cosine of the result from Step 4. Multiply it by -23.44, the tilt of the Earth&#8217;s axis in degrees. The result is the solar declination in degrees for that day of the year. From the example, the cosine of 53.2603 is 0.5982; multiply it by -23.44 to get -14.02 degrees.\n<\/p><\/blockquote>\n<p> &#8230; advice, to be able to piece together a quite acceptable online method of calculating these &#8220;sun declinations&#8221;.<\/p>\n<p>That was that, the mathematics of it, where &#8220;the net&#8221; is so good at offering advice, but &#8220;inhouse integration&#8221; of web applications, that is another matter entirely, and as we&#8217;ve noted before, often, integration of existant arrangements can be harder work that starting from scratch &#8230; bit like renovating (versus building from vacant land), quite often?!<\/p>\n<p>Today&#8217;s integration is a bit rare, in that between two pieces of functionality, the integrations are two-way &#8230; <b>so that<\/b> &#8230;<\/p>\n<ul>\n<li>Sun Information project&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php\" title=\"Click picture\">live run<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/sun_information.php--GETME\" title=\"sun_information.php\">sun_information.php<\/a>&#8216;s <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\">changed<\/a> source code <b>is given the sun angle diagram of<\/b> the &#8230;<\/li>\n<li>Sun Angle project&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/SunAngle\/sun_angle_now_at.php\" title=\"Click picture\">live run<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/SunAngle\/sun_angle_now_at.php-----GETME\" title=\"sun_angle_now_at.php\">sun_angle_now_at.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/SunAngle\/sun_angle_now_at.php-----GETME\" title=\"sun_angle_now_at.php\">changed<\/a> source code <b>is given the sunset, sunrise, sun transit time information<\/b> of the web application above<\/li>\n<\/ul>\n<p>We hope you try out some of this PHP work.<\/p>\n<hr>\n<p id='phpsitzt'>Previous relevant <a target=_blank title='PHP Sun Information TimeZone Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/php-sun-information-timezone-tutorial\/'>PHP Sun Information TimeZone 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 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<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='#d35675' onclick='var dv=document.getElementById(\"d35675\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/integration\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d35675' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We left off the project of PHP Sun Information TimeZone Tutorial recently adding in that fourth (time) dimension link via the use of TimeZones, and today, that &#8230; Sun Information is integrated into &#8230; Sun Angle project &#8230; and vice &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-sun-information-software-integration-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,14,37],"tags":[212,213,301,302,2446,392,481,483,614,652,684,719,752,932,997,1122,1168,2445,1279,1693,1319],"class_list":["post-35675","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-client","tag-clientserver","tag-date","tag-datetime","tag-ecma","tag-equation","tag-geographicals","tag-geolocation","tag-integration","tag-javascript","tag-latitude","tag-longitude","tag-mathematics","tag-php","tag-programming","tag-server","tag-software-integration","tag-sun","tag-time","tag-timezone","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35675"}],"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=35675"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35675\/revisions"}],"predecessor-version":[{"id":35685,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35675\/revisions\/35685"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=35675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=35675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=35675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}