[dev] Patch for moon block

Jason Rust jrust at rustyparts.com
Wed Jan 7 10:16:18 PST 2004


The attached patch allows the moon block to still work when the calendar
extension is not compiled into PHP.
-Jason
-------------- next part --------------
Index: moon.php
===================================================================
RCS file: /repository/horde/lib/Block/moon.php,v
retrieving revision 1.6
diff -u -r1.6 moon.php
--- moon.php	29 Oct 2003 03:38:43 -0000	1.6
+++ moon.php	7 Jan 2004 18:05:56 -0000
@@ -147,7 +147,7 @@
             $F -= intval($F);
             /* Convert from JD to Calendar Date. */
             $julian = $J + round($F);
-            $parts  = explode('/', jdtogregorian($julian));
+            $parts  = explode('/', $this->_jdtogregorian($julian));
             $stamp  = gmmktime(0, 0, 0, $parts[0], $parts[1], $parts[2]);
             /* half K. */
             if (($K9 - floor($K9)) > 0) {
@@ -170,5 +170,45 @@
         }
         return $phases;
     }
+    
+    /**
+     * Checks if the jdtogregorian function exists, and if not
+     * calculates the gregorian date manually.
+     *
+     * @param int $julian The julian date
+     *
+     * @access public
+     * @return string m/d/Y
+     */
+    function _jdtogregorian($julian)
+    {
+        if (function_exists('jdtogregorian')) {
+            return jdtogregorian($julian);
+        }
+        else {
+            // From http://php.net/manual/en/function.jdtogregorian.php
+            $julian = $julian - 1721119;
+            $calc1 = 4 * $julian - 1;
+            $year = floor($calc1 / 146097);
+            $julian = floor($calc1 - 146097 * $year);
+            $day = floor($julian / 4);
+            $calc2 = 4 * $day + 3;
+            $julian = floor($calc2 / 1461);
+            $day = $calc2 - 1461 * $julian;
+            $day = floor(($day + 4) / 4);
+            $calc3 = 5 * $day - 3;
+            $month = floor($calc3 / 153);
+            $day = $calc3 - 153 * $month;
+            $day = floor(($day + 5) / 5);
+            $year = 100 * $year + $julian;
 
+            if ($month < 10) {
+                $month = $month + 3;
+            } else {
+                $month = $month - 9;
+                $year = $year + 1;
+            }
+            return "$day/$month/$year";
+        }
+    }
 }


More information about the dev mailing list