PHP Classes

This is a very useful class.

Recommend this page to a friend!

      Sun  >  All threads  >  This is a very useful class.  >  (Un) Subscribe thread alerts  
Subject:This is a very useful class.
Summary:Package rating comment
Author:Brian Beinlich
Date:2007-10-19 15:36:42

Brian Beinlich rated this package as follows:

Utility: Good
Consistency: Good
Documentation: Not sure
Examples: Sufficient

  1. This is a very useful class.   Reply   Report abuse  
Picture of Brian Beinlich Brian Beinlich - 2007-10-19 15:36:42
This is a very useful class. However, there are three issues that are worth mentioning.
First, the day-of-year calculation is off by 1. The original algorithm evaluates January 1 as day 1. The class (actually, PHP's date function) evaluates it to 0, so it is necessary to add one to the day of year to get the correct day.
The second is that the class assumes that the timestamp passed in corresponds to midnight of the desired day. If it is not, the sunrise/set time is ADDED to the date you pass in, which will give you incorrect results. So it is NOT OK to just pass in time() as the timestamp -- you will get incorrect answers. I suggest that the author add code to remove any hours/minutes/seconds from the passed date.
The third is more subtle, and is a property of the algorithm, not its implementation by the author. The algorithm returns a sunset time that is smaller (i.e., earlier) than the sunrise time. For example, here in Portland, Oregon, and using timezone=0 to see results in UTC, the sunrise ($ut) is about 14, but the sunset is about 1. Thus sunset comes earlier than sunrise! This is not normally a problem unless one is trying to calculate sr/ss on the daylight savings time transition day, in which case the sunset will land on the previous day, and the wrong DST offset would be applied. The fix for this is left as an exercise for the interested reader. :-)