gregseth / suncalc-php

PHP library for basic astronomical computation (sun and moon rise and set, moon phases, …)
GNU General Public License v2.0
65 stars 20 forks source link

moonset occasionally causing fatal erorr #13

Open dmvictoria opened 6 years ago

dmvictoria commented 6 years ago

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

MenoData commented 6 years ago

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.

iacyn commented 5 years ago

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