Reputation: 3189
Is there a way to get sunrise and sunset times in PHP without having to deal with Zenith and GMT offsets?
The functions date_sunrise()
and date_sun()
asks for zenith and GMT which I don't want to deal with.
Ideally I would simply write someSunriseFunction(<latitude>, <longitude>, <timezone>)
i.e. someSunriseFunction(34.30, -118.15, 'EST')
would be for Los Angeles.
Thanks.
Upvotes: 1
Views: 4413
Reputation: 4216
Unfortunately there is no easy way to get the sunrise and sunset using the above. There is alot that goes into the calculation. The full Calculation can be found here: http://en.wikipedia.org/wiki/Sunrise_equation#Complete_calculation_on_Earth
If it may be easier give the user a list of citys with predefined values for Zenith, GMT, LAtitude and Longitude. This can either be some flat file, object, or database driven.
I have used this and used a script to offset for Daylight Savings Time
Upvotes: 0
Reputation: 522597
The timezone is pretty useless for this function. That information is already included in the latitude and longitude. What you need is the location and a timestamp, because the sun sets and rises at different times at different times of the year.
And that's exactly what date_sun_info
gives you:
date_sun_info ( int $time , float $latitude , float $longitude )
Upvotes: 6