suncalc-php
suncalc-php copied to clipboard
moonset occasionally causing fatal erorr
Hi!
I have a site with every location in the world and I use suncalc to display sunrise/sunset moonrise/moonset. But randomly, several locations every day will get a fatal error and not load:
Fatal error: Call to a member function format() on a non-object in...
It seems only the moonset object is missing, the other sunrise/sunset and moonrise objects load fine. For now my fix is this:
if(is_object($moonTimes['moonset']))
{
$moonset = $moonTimes['moonset']->format($hour_min_format);
}
at least that stops my page from crashing.
Thanks.
PS love the script by the way :)
The moon does not rise or set every day. This behaviour is caused by the fact that there is not just the earth rotation around its axis but also the revolution of the moon around the earth at the same time. This results in about 50 minutes shifting of moon rise/set times every calendar day.
It's actually happened to me when the moonrise was 00:55 at UTC+1 I use, but works fine in every other timezone I tested
Edit : I set $t->setTime((0, 0, 0);
line 210, into $t->setTime((date('O')/100), 0, 0);
, now it works fine