]> git.mjollnir.org Git - s9y.git/commitdiff
some bugs in persian_mktime temporary fixed!
authoromidmottaghi <omidmottaghi>
Sun, 9 Jul 2006 22:55:01 +0000 (22:55 +0000)
committeromidmottaghi <omidmottaghi>
Sun, 9 Jul 2006 22:55:01 +0000 (22:55 +0000)
include/functions_calendars.inc.php

index d0f597e5b1dd13cf2adf9c1de974da6052c75114..102fe84d61987139dd77be4d88135c5335ba79c8 100644 (file)
@@ -426,7 +426,7 @@ function persian_date_utf($format, $timestamp='') {
 
 /**
  * Create a Unix timestamp for a Persian date
- * This function only works with month >= 0 and day > 0
+ * This function works only with day > 0
  *
  * @author Omid Mottaghi
  * @access public
@@ -440,6 +440,8 @@ function persian_date_utf($format, $timestamp='') {
  * @return  int returned timestamp
  */
 function persian_mktime($hour='', $min='', $sec='', $mon='', $day='', $year='', $is_dst=-1){
+       $j_days_in_month = array(, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
+       
        if ( (string) $hour == '') { $hour = persian_date_utf('H'); }
        if ( (string) $min  == '') { $min  = persian_date_utf('i'); }
        if ( (string) $sec  == '') { $sec  = persian_date_utf('s'); }
@@ -447,24 +449,62 @@ function persian_mktime($hour='', $min='', $sec='', $mon='', $day='', $year='',
        if ( (string) $mon  == '') { $mon  = persian_date_utf('n'); }
        if ( (string) $year == '') { $year = persian_date_utf('Y'); }
        
-       // these lines is temporary
-       if($mon == 0){
-               $year --;
-               $mon = 12;
-       }
+       /* 
+          an ugly, beta code snippet to support days <= zero!
+          it should work, but days in one or more months should calculate!
+       */
        
-       /*if($mon <= 0){
-               // change sign and plus one!
-               $mon = abs($mon) + 1;
-               echo $mon.'<br>';
-               // calculate years and months that should be decreased
-               $years  = floor($mon/12) + 1;
-               $months = ($years*12) - $mon + 1;
-               echo $years.'<br>';
-               die($months);
+       /*
+       if($day <= 0){
+               // change sign
+               $day = abs($day);
+               
+               // calculate months and days that shall decrease
+               // this do-while has a lot of errors!!!
+               do{
+                       // $month_days = $j_days_in_month[$mon]
+                       $months  = floor($day/30);
+                       $days = $day % 30;
+               }while();
+               
+               $mon -= $months;
+               $day -= $days;
+               if ($day < 1) {
+                       $mon--;
+               }
+       }
+       */
+
+       if($mon <= 0){
+               // change sign
+               $mon = abs($mon);
+               
+               // calculate years and months that shall decrease
+               $years  = floor($mon/12);
+               $months = $mon % 12;
+               
                $year -= $years;
-               $mon  = $months;
-       }*/
+               $mon  -= $months;
+               if ($mon < 1) {
+                       $year--;
+                       $mon += 12;
+               }
+       }
+       
+       if ($day < 1) {
+               $temp_month = $mon-1;
+               $temp_year  = $year;
+               if($temp_month <= 0){
+                       $temp_month = 12;
+                       $temp_year--;
+               }
+               if ($temp_month>1 && (($temp_year%4==0 && $temp_year%100!=0) || ($temp_year%400==0))){
+               $j_days_in_month[12] = 30;
+       }else{
+               $j_days_in_month[12] = 29;
+       }
+               $day += $j_days_in_month[$temp_month];
+       }
        
     list($year, $mon, $day)=p2g($year, $mon, $day);
     return mktime($hour, $min, $sec, $mon, $day, $year, $is_dst);