[geeklog-cvs] geeklog-1.3/public_html lib-common.php,1.331,1.332
tony at iowaoutdoors.org
tony at iowaoutdoors.org
Fri Jun 4 17:47:31 EDT 2004
Update of /var/cvs/geeklog-1.3/public_html
In directory www:/tmp/cvs-serv22181
Modified Files:
lib-common.php
Log Message:
Added a date diff function needed for PDF garbage collection.
Index: lib-common.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/lib-common.php,v
retrieving revision 1.331
retrieving revision 1.332
diff -C2 -d -r1.331 -r1.332
*** lib-common.php 31 May 2004 18:22:50 -0000 1.331
--- lib-common.php 4 Jun 2004 21:47:28 -0000 1.332
***************
*** 5736,5739 ****
--- 5736,5831 ----
}
+ /**
+ * Determines the difference between to dates.
+ *
+ * This will takes either unixtimestamps or English dates as input and will
+ * automatically do the date diff on the more recent of the two dates (e.g. the
+ * order of the two dates given doesn't matter).
+ *
+ * @author Tony Bibbs <tony.bibbs at iowa.gov
+ * @access public
+ * @param string $interval Can be:
+ * y = year
+ * m = month
+ * w = week
+ * h = hours
+ * i = minutes
+ * s = seconds
+ * @param string|int $date1 English date (e.g. 10 Dec 2004) or unixtimestamp
+ * @param string|int $date2 English date (e.g. 10 Dec 2004) or unixtimestamp
+ * @return int Difference of the two dates in the unit of time indicated by the interval
+ *
+ */
+ function COM_dateDiff($interval, $date1, $date2)
+ {
+ // Convert dates to timestamps, if needed.
+ if (!is_numeric($date1)) {
+ $date1 = strtotime($date1);
+ }
+
+ if (!is_numeric($date2)) {
+ $date2 = strtotime($date2);
+ }
+
+ // Function roughly equivalent to the ASP "DateDiff" function
+ if ($date2 > $date1) {
+ $seconds = $date2 - $date1;
+ } else {
+ $seconds = $date1 - $date2;
+ }
+
+ switch($interval) {
+ case "y":
+ list($year1, $month1, $day1) = split('-', date('Y-m-d', $date1));
+ list($year2, $month2, $day2) = split('-', date('Y-m-d', $date2));
+ $time1 = (date('H',$date1)*3600) + (date('i',$date1)*60) + (date('s',$date1));
+ $time2 = (date('H',$date2)*3600) + (date('i',$date2)*60) + (date('s',$date2));
+ $diff = $year2 - $year1;
+ if($month1 > $month2) {
+ $diff -= 1;
+ } elseif($month1 == $month2) {
+ if($day1 > $day2) {
+ $diff -= 1;
+ } elseif($day1 == $day2) {
+ if($time1 > $time2) {
+ $diff -= 1;
+ }
+ }
+ }
+ break;
+ case "m":
+ list($year1, $month1, $day1) = split('-', date('Y-m-d', $date1));
+ list($year2, $month2, $day2) = split('-', date('Y-m-d', $date2));
+ $time1 = (date('H',$date1)*3600) + (date('i',$date1)*60) + (date('s',$date1));
+ $time2 = (date('H',$date2)*3600) + (date('i',$date2)*60) + (date('s',$date2));
+ $diff = ($year2 * 12 + $month2) - ($year1 * 12 + $month1);
+ if($day1 > $day2) {
+ $diff -= 1;
+ } elseif($day1 == $day2) {
+ if($time1 > $time2) {
+ $diff -= 1;
+ }
+ }
+ break;
+ case "w":
+ // Only simple seconds calculation needed from here on
+ $diff = floor($seconds / 604800);
+ break;
+ case "d":
+ $diff = floor($seconds / 86400);
+ break;
+ case "h":
+ $diff = floor($seconds / 3600);
+ break;
+ case "i":
+ $diff = floor($seconds / 60);
+ break;
+ case "s":
+ $diff = $seconds;
+ break;
+ }
+ return $diff;
+ }
+
// Now include all plugin functions
More information about the geeklog-cvs
mailing list