some bugs in persian_mktime temporary fixed!
authoromidmottaghi <omidmottaghi>
Wed, 12 Apr 2006 04:17:16 +0000 (04:17 +0000)
committeromidmottaghi <omidmottaghi>
Wed, 12 Apr 2006 04:17:16 +0000 (04:17 +0000)
include/functions_calendars.inc.php
index.php

index e25ffae99a17433dd87443b9b7282312c5357e3f..4db62d753b2093eec03dd02d0fae9e2a268558a2 100644 (file)
@@ -2,11 +2,6 @@
 # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
 # All rights reserved.  See LICENSE file for licensing details
 
-if (defined('S9Y_FRAMEWORK_CALENDARS')) {
-    return;
-}
-@define('S9Y_FRAMEWORK_CALENDARS', true);
-
 /**
  * Gregorian to Persian Convertor
  *
@@ -265,9 +260,13 @@ function persian_strftime_utf($format, $timestamp) {
  * @param   int     Timestamp to format
  * @return  string  Formatted local time/date
  */
-function persian_date_utf($format, $timestamp) {
+function persian_date_utf($format, $timestamp='') {
     
-    $g_d=date('j', $timestamp);
+    if($timestamp==''){
+       $timestamp = mktime();
+    }
+       
+       $g_d=date('j', $timestamp);
     $g_m=date('n', $timestamp);
     $g_y=date('Y', $timestamp);
     
@@ -417,6 +416,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
  *
  * @author Omid Mottaghi
  * @access public
@@ -429,7 +429,33 @@ function persian_date_utf($format, $timestamp) {
  * @param   int is daylight savings time set?
  * @return  int returned timestamp
  */
-function persian_mktime($hour=0, $min=0, $sec=0, $mon=1, $day=1, $year=1349, $is_dst=-1){
+function persian_mktime($hour='', $min='', $sec='', $mon='', $day='', $year='', $is_dst=-1){
+       if ( (string) $hour == '') { $hour = persian_date_utf('H'); }
+       if ( (string) $min  == '') { $min  = persian_date_utf('i'); }
+       if ( (string) $sec  == '') { $sec  = persian_date_utf('s'); }
+       if ( (string) $day  == '') { $day  = persian_date_utf('j'); }
+       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;
+       }
+       
+       /*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);
+               $year -= $years;
+               $mon  = $months;
+       }*/
+       
     list($year, $mon, $day)=p2g($year, $mon, $day);
     return mktime($hour, $min, $sec, $mon, $day, $year, $is_dst);
 }
index 561b24c6c329a5afbd791428f424a085b074f3cf..230b7a50ccc781dd12a3d153a8f25aae38363c2c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -190,7 +190,7 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range
                 }
             }
 
-            list($year, $month, $day) = j2g ($year, $month, $day);
+            list($year, $month, $day) = p2g ($year, $month, $day);
             break;
     }