Skip to content

Commit

Permalink
Sunrise sunset converter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbig committed Jun 3, 2016
1 parent a6c095e commit 99e1125
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions converter/sunrise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Generates the sunrise/sunset table
*/
date_default_timezone_set('UTC');
$timestamp = new DateTime('2016-01-01 12:00:00');


$values = [];
for ($i=0; $i<365; $i++) {
$day = ($timestamp->format('m')-1) * 30 + $timestamp->format('d') -1;

$sunrise = date_sunrise($timestamp->getTimestamp(), SUNFUNCS_RET_STRING, 47.33, 19);
$sunset = date_sunset($timestamp->getTimestamp(), SUNFUNCS_RET_STRING, 47.33, 19);

$timestamp->add(new DateInterval('P1D'));

$values[$day] = [toInt($sunrise), toInt($sunset)];
}

// feb 29
$values[59] = $values[58];
ksort($values);

echo '{';
echo implode(", ", array_map(
function ($v) {
return '{' . implode(', ', $v) . '}';
},
$values
));
echo '}', "\n";
function toInt($str) {
list($hour, $minute) = explode(':', $str);
return $hour * 60 + $minute;
}

0 comments on commit 99e1125

Please sign in to comment.