Code

added comparison test for two dates.
authorhzerres <hzerres@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 8 Sep 2010 12:57:55 +0000 (12:57 +0000)
committerhzerres <hzerres@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 8 Sep 2010 12:57:55 +0000 (12:57 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19564 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/utils/class_tests.inc

index e1f87a0d47ec402ec9ac52c91671935839a18618..03b7bf696a4b4465c502fc1acbb079f41bdeebd7 100644 (file)
@@ -292,7 +292,33 @@ class tests {
 
     return checkdate($matches[2],$matches[1],$matches[3]);
   }
-
+  /*
+   * Compares two dates
+   * 
+   * <0 => a<b
+   * 0 => a=b
+   * >0 => a>b
+   * 
+   * 
+   */
+ public static function compareDate($dateA, $dateB){
+        /*
+         * TODO:
+         * use $lang to check date format      
+         */ 
+       $tstampA = strtotime($dateA);
+       if($tstampA === false){
+               trigger_error("Given date can not be converted to timestamp(".$dataA.") in function tests::compareDate.");
+               return false;   
+       }
+       $tstampB = strtotime($dateB);
+       if($tstampB === false){
+               trigger_error("Given date can not be converted to timestamp(".$dataB.") in function tests::compareDate.");
+               return false;   
+       }
+       
+       return $tstampA-$tstampB;
+ }
   /* \brief Check if the specified IP address $address is inside the given network */
   public static function is_in_ip_range($from, $to, $address)
   {