suncalc-php icon indicating copy to clipboard operation
suncalc-php copied to clipboard

moonset occasionally causing fatal erorr

Open dmvictoria opened this issue 6 years ago • 2 comments

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 :)

dmvictoria avatar Oct 28 '17 18:10 dmvictoria

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.

MenoData avatar Feb 19 '18 16:02 MenoData

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

iacyn avatar May 09 '19 09:05 iacyn