# 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
*
* @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);
/**
* Create a Unix timestamp for a Persian date
+ * This function only works with month >= 0 and day > 0
*
* @author Omid Mottaghi
* @access public
* @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);
}