From: omidmottaghi Date: Mon, 27 Feb 2006 11:18:46 +0000 (+0000) Subject: Persian calendar debugged X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3323fd95f81a9214fa4db9161beb312cabe70305;p=s9y.git Persian calendar debugged --- diff --git a/include/functions.inc.php b/include/functions.inc.php index 0310599..dacc7e1 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -87,7 +87,7 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { } return strftime($format, $timestamp); - case 'jalali-utf8': + case 'persian-utf8': if ($timestamp == null) { $timestamp = serendipity_serverOffsetHour(); } elseif ($useOffset) { @@ -95,7 +95,7 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { } require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; - return jalali_strftime_utf($format, $timestamp); + return persian_strftime_utf($format, $timestamp); } } diff --git a/include/functions_calendars.inc.php b/include/functions_calendars.inc.php index e347b5f..6e2008f 100644 --- a/include/functions_calendars.inc.php +++ b/include/functions_calendars.inc.php @@ -3,7 +3,7 @@ # All rights reserved. See LICENSE file for licensing details /** - * Gregorian to Jalali Convertor + * Gregorian to Persian Convertor * * @author farsiweb.info * @access public @@ -12,7 +12,7 @@ * @param int day * @return array converted time */ -function g2j($g_y, $g_m, $g_d){ +function g2p($g_y, $g_m, $g_d){ $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); @@ -55,7 +55,7 @@ function g2j($g_y, $g_m, $g_d){ } /** - * Jalali to Gregorian Convertor + * Persian to Gregorian Convertor * * @author farsiweb.info * @access public @@ -64,7 +64,7 @@ function g2j($g_y, $g_m, $g_d){ * @param int day * @return array converted time */ -function j2g($j_y, $j_m, $j_d){ +function p2g($j_y, $j_m, $j_d){ $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); $jy = $j_y-979; @@ -107,7 +107,7 @@ function j2g($j_y, $j_m, $j_d){ } /** - * Format a string according to Jalali calendar (UTF) + * Format a string according to Persian calendar (UTF) * * @author Omid Mottaghi * @access public @@ -115,13 +115,13 @@ function j2g($j_y, $j_m, $j_d){ * @param int Timestamp to format * @return string Formatted local time/date according to locale settings */ -function jalali_strftime_utf($format, $timestamp) { +function persian_strftime_utf($format, $timestamp) { $g_d=date('j', $timestamp); $g_m=date('n', $timestamp); $g_y=date('Y', $timestamp); - list($jy, $jm, $jd, $j_all_days) = g2j($g_y, $g_m, $g_d); + list($jy, $jm, $jd, $j_all_days) = g2p($g_y, $g_m, $g_d); $j_month_name = array('', 'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'); @@ -167,7 +167,7 @@ function jalali_strftime_utf($format, $timestamp) { $output_str.=$j_month_name[$jm]; break; case 'c': - $output_str.=jalali_strftime_utf('%y/%m/%d %I:%M:%S', $timestamp); + $output_str.=persian_strftime_utf('%y/%m/%d %I:%M:%S', $timestamp); break; case 'C': $output_str.=floor($jy/100); @@ -188,7 +188,7 @@ function jalali_strftime_utf($format, $timestamp) { $output_str.=date('h', $timestamp); break; case 'j': - $output_str.=sprintf("%03d", $j_all_days); + $output_str.=sprintf('%03d', $j_all_days); break; case 'm': if($jm<10) $output_str.='0'.$jm; else $output_str.=$jm; @@ -215,17 +215,17 @@ function jalali_strftime_utf($format, $timestamp) { case 'U': case 'V': case 'W': - $output_str.=sprintf("%02d", floor(($j_all_days+1)/7)); + $output_str.=sprintf('%02d', floor(($j_all_days+1)/7)); break; case 'u': case 'w': $output_str.=$j_week_number[date('D', $timestamp)]; break; case 'x': - $output_str.=jalali_strftime_utf('%y/%m/%d', $timestamp); + $output_str.=persian_strftime_utf('%y/%m/%d', $timestamp); break; case 'X': - $output_str.=jalali_strftime_utf('%I:%M:%S', $timestamp); + $output_str.=persian_strftime_utf('%I:%M:%S', $timestamp); break; case 'g': case 'y': @@ -252,7 +252,7 @@ function jalali_strftime_utf($format, $timestamp) { } /** - * Format a string according to Jalali calendar (UTF) + * Format a string according to Persian calendar (UTF) * * @author Omid Mottaghi * @access public @@ -260,16 +260,20 @@ function jalali_strftime_utf($format, $timestamp) { * @param int Timestamp to format * @return string Formatted local time/date */ -function jalali_date_utf($format, $timestamp) { +function persian_date_utf($format, $timestamp) { $g_d=date('j', $timestamp); $g_m=date('n', $timestamp); $g_y=date('Y', $timestamp); - list($jy, $jm, $jd, $j_all_days) = g2j($g_y, $g_m, $g_d); + list($jy, $jm, $jd, $j_all_days) = g2p($g_y, $g_m, $g_d); $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); - if(($g_y % 4) == 3) $j_days_in_month[12]++; + $leap = 0; + if ($g_m>1 && (($g_y%4==0 && $g_y%100!=0) || ($g_y%400==0))){ + $j_days_in_month[12]++; + $leap = 1; + } $j_month_name = array('', 'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'); @@ -320,7 +324,7 @@ function jalali_date_utf($format, $timestamp) { $output_str.=$j_week_number[date('D', $timestamp)]; break; case 'z': - $output_str.=sprintf("%03d", $j_all_days); + $output_str.=sprintf('%03d', $j_all_days); break; case 'W': $output_str.=floor(($j_all_days+1)/7); @@ -337,7 +341,8 @@ function jalali_date_utf($format, $timestamp) { case 't': $output_str.=$j_days_in_month[$jm]; break; - case 'L': // incomplete + case 'L': + return $leap; break; case 'o': case 'Y': @@ -351,7 +356,7 @@ function jalali_date_utf($format, $timestamp) { if(date('a', $timestamp)=='pm') $output_str.='بعد از ظهر'; else $output_str.='قبل از ظهر'; break; case 'B': - $output_str.=date('a', $timestamp); + $output_str.=date('B', $timestamp); break; case 'g': $output_str.=date('g', $timestamp); @@ -371,6 +376,9 @@ function jalali_date_utf($format, $timestamp) { case 's': $output_str.=date('s', $timestamp); break; + case 'e': + $output_str.=date('e', $timestamp); + break; case 'I': $output_str.=date('I', $timestamp); break; @@ -381,10 +389,10 @@ function jalali_date_utf($format, $timestamp) { $output_str.=date('Z', $timestamp); break; case 'c': - $output_str.=date('d-m-Y\TH:i:sO', $timestamp); + $output_str.=persian_date_utf('d-m-Y\TH:i:sO', $timestamp); break; case 'r': - $output_str.=date('D، j F Y H:i:s O', $timestamp); + $output_str.=persian_date_utf('D، j F Y H:i:s O', $timestamp); break; case 'U': $output_str.=date('U', $timestamp); @@ -403,7 +411,7 @@ function jalali_date_utf($format, $timestamp) { } /** - * Create a Unix timestamp for a Jalali date + * Create a Unix timestamp for a Persian date * * @author Omid Mottaghi * @access public @@ -416,7 +424,7 @@ function jalali_date_utf($format, $timestamp) { * @param int is daylight savings time set? * @return int returned timestamp */ -function jalali_mktime($hour=0, $min=0, $sec=0, $mon=1, $day=1, $year=1349, $is_dst=-1){ - list($year, $mon, $day)=j2g($year, $mon, $day); +function persian_mktime($hour=0, $min=0, $sec=0, $mon=1, $day=1, $year=1349, $is_dst=-1){ + list($year, $mon, $day)=p2g($year, $mon, $day); return mktime($hour, $min, $sec, $mon, $day, $year, $is_dst); } diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 1b7544e..5f28ebf 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -1344,12 +1344,12 @@ function serendipity_printArchives() { $thisYear = date('Y', serendipity_serverOffsetHour()); $thisMonth = date('m', serendipity_serverOffsetHour()); break; - case 'jalali-utf8': + case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; - $lastYear = jalali_date_utf('Y', serendipity_serverOffsetHour($f[0][0])); - $lastMonth = jalali_date_utf('m', serendipity_serverOffsetHour($f[0][0])); - $thisYear = jalali_date_utf('Y', serendipity_serverOffsetHour()); - $thisMonth = jalali_date_utf('m', serendipity_serverOffsetHour()); + $lastYear = persian_date_utf('Y', serendipity_serverOffsetHour($f[0][0])); + $lastMonth = persian_date_utf('m', serendipity_serverOffsetHour($f[0][0])); + $thisYear = persian_date_utf('Y', serendipity_serverOffsetHour()); + $thisMonth = persian_date_utf('m', serendipity_serverOffsetHour()); break; } $max = 0; @@ -1383,10 +1383,10 @@ function serendipity_printArchives() { $s = serendipity_serverOffsetHour(mktime(0, 0, 0, $m, 1, $y), true); $e = serendipity_serverOffsetHour(mktime(23, 59, 59, $m, date('t', $s), $y), true); break; - case 'jalali-utf8': + case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; - $s = serendipity_serverOffsetHour(jalali_mktime(0, 0, 0, $m, 1, $y), true); - $e = serendipity_serverOffsetHour(jalali_mktime(23, 59, 59, $m, date('t', $s), $y), true); + $s = serendipity_serverOffsetHour(persian_mktime(0, 0, 0, $m, 1, $y), true); + $e = serendipity_serverOffsetHour(persian_mktime(23, 59, 59, $m, date('t', $s), $y), true); break; } diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index cd49648..d0945a3 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -93,41 +93,41 @@ class serendipity_calendar_plugin extends serendipity_plugin { break; - case 'jalali-utf8': + case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; list(,$jy, $jm, $jd) = $serendipity['uriArguments']; if( isset($jd) && $jd ){ - list ( $gy, $gm, $gd ) = j2g ($jy, $jm, $jd); + list ( $gy, $gm, $gd ) = p2g ($jy, $jm, $jd); }elseif( isset($jm) && $jm ){ - list ( $gy, $gm, $gd ) = j2g ( $jy, $jm, 1); + list ( $gy, $gm, $gd ) = p2g ( $jy, $jm, 1); }else{ $gy = $year; $gm = $month; $gd = (int) date('d'); } - list ( $year, $month, $day ) = g2j ($gy, $gm, $gd); + list ( $year, $month, $day ) = g2p ($gy, $gm, $gd); // How many days does the month have? $ts = strtotime($gy . '-' . sprintf('%02d', $gm) . '-' . sprintf('%02d', $gd)); $now = serendipity_serverOffsetHour(time()); - $nrOfDays = jalali_strftime_utf('%m', $ts); + $nrOfDays = persian_strftime_utf('%m', $ts); $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); if ($year%4 == 3 && $nrOfDays == 12) $nrOfDays = $j_days_in_month[(int)$nrOfDays]+1; else $nrOfDays = $j_days_in_month[(int)$nrOfDays]; // Calculate first timestamp of the month - list ($firstgy, $firstgm, $firstgd ) = j2g ( $year, $month, 1); + list ($firstgy, $firstgm, $firstgd ) = p2g ( $year, $month, 1); $firstts = mktime (0, 0, 0, $firstgm, $firstgd, $firstgy); - // Calculate first Jalali day, week day name + // Calculate first persian day, week day name $firstDayWeekDay = date('w', $firstts); // Calculate end timestamp of the month - list ( $end_year, $end_month, $end_day ) = j2g ($year, $month+1, 1); + list ( $end_year, $end_month, $end_day ) = p2g ($year, $month+1, 1); $endts = mktime(0, 0, 0, $end_month, $end_day, $end_year); break; } // end switch @@ -219,17 +219,17 @@ class serendipity_calendar_plugin extends serendipity_plugin { $today_year = date('Y', $now); break; - case 'jalali-utf8': + case 'persian-utf8': $activeDays = array(); if (is_array($rows)) { foreach ($rows as $row) { $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); - $activeDays[(int) jalali_date_utf('j', $row['timestamp'])] = $row['timestamp']; + $activeDays[(int) persian_date_utf('j', $row['timestamp'])] = $row['timestamp']; } } - $today_day = jalali_date_utf('j', $now); - $today_month = jalali_date_utf('m', $now); - $today_year = jalali_date_utf('Y', $now); + $today_day = persian_date_utf('j', $now); + $today_month = persian_date_utf('m', $now); + $today_year = persian_date_utf('Y', $now); break; } // end switch @@ -427,10 +427,10 @@ class serendipity_archives_plugin extends serendipity_plugin { $ts_title = serendipity_formatTime("%B %Y", $ts, false); $ts = mktime(0, 0, 0, date('m', $ts)-1, 1, date('Y', $ts)); // Must be last in 'case' statement break; - case 'jalali-utf8': - $linkStamp = jalali_date_utf('Y/m', $ts); + case 'persian-utf8': + $linkStamp = persian_date_utf('Y/m', $ts); $ts_title = serendipity_formatTime("%B %Y", $ts, false); - $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $ts)-1, 1, jalali_date_utf('Y', $ts)); // Must be last in 'case' statement + $ts = persian_mktime(0, 0, 0, persian_date_utf('m', $ts)-1, 1, persian_date_utf('Y', $ts)); // Must be last in 'case' statement break; } break; @@ -442,10 +442,10 @@ class serendipity_archives_plugin extends serendipity_plugin { $ts_title = WEEK . ' '. date('W, Y', $ts); $ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-7, date('Y', $ts)); break; - case 'jalali-utf8': - $linkStamp = jalali_date_utf('Y/\WW', $ts); - $ts_title = WEEK . ' '. jalali_date_utf('W، Y', $ts); - $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $ts), jalali_date_utf('d', $ts)-7, jalali_date_utf('Y', $ts)); + case 'persian-utf8': + $linkStamp = persian_date_utf('Y/\WW', $ts); + $ts_title = WEEK . ' '. persian_date_utf('W، Y', $ts); + $ts = persian_mktime(0, 0, 0, persian_date_utf('m', $ts), persian_date_utf('d', $ts)-7, persian_date_utf('Y', $ts)); break; } break; @@ -457,10 +457,10 @@ class serendipity_archives_plugin extends serendipity_plugin { $ts_title = serendipity_formatTime("%B %e. %Y", $ts, false); $ts = mktime(0, 0, 0, date('m', $ts), date('d', $ts)-1, date('Y', $ts)); // Must be last in 'case' statement break; - case 'jalali-utf8': - $linkStamp = jalali_date_utf('Y/m/d', $ts); + case 'persian-utf8': + $linkStamp = persian_date_utf('Y/m/d', $ts); $ts_title = serendipity_formatTime("%e %B %Y", $ts, false); - $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $ts), jalali_date_utf('d', $ts)-1, jalali_date_utf('Y', $ts)); // Must be last in 'case' statement + $ts = persian_mktime(0, 0, 0, persian_date_utf('m', $ts), persian_date_utf('d', $ts)-1, persian_date_utf('Y', $ts)); // Must be last in 'case' statement break; } break; diff --git a/index.php b/index.php index b2253e6..9e9677d 100644 --- a/index.php +++ b/index.php @@ -150,7 +150,7 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range } break; - case 'jalali-utf8': + case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; $gday = 1; if ($week) { @@ -171,21 +171,21 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range } } - $tm = jalali_mktime(0, 0, 0, $i, $day, $year); - $ts = jalali_mktime(0, 0, 0, jalali_date_utf('m', $tm), jalali_date_utf('j', $tm), $year); - $te = jalali_mktime(23, 59, 59, jalali_date_utf('m', $tm), jalali_date_utf('j', $tm)+7, $year); + $tm = persian_mktime(0, 0, 0, $i, $day, $year); + $ts = persian_mktime(0, 0, 0, persian_date_utf('m', $tm), persian_date_utf('j', $tm), $year); + $te = persian_mktime(23, 59, 59, persian_date_utf('m', $tm), persian_date_utf('j', $tm)+7, $year); $date = serendipity_formatTime(WEEK .' '. $week .'، %Y', $ts, false); } else { if ($day) { - $ts = jalali_mktime(0, 0, 0, $month, $day, $year); - $te = jalali_mktime(23, 59, 59, $month, $day, $year); + $ts = persian_mktime(0, 0, 0, $month, $day, $year); + $te = persian_mktime(23, 59, 59, $month, $day, $year); $date = serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false); } else { - $ts = jalali_mktime(0, 0, 0, $month, $gday, $year); + $ts = persian_mktime(0, 0, 0, $month, $gday, $year); if (!isset($gday2)) { - $gday2 = jalali_date_utf('t', $ts); + $gday2 = persian_date_utf('t', $ts); } - $te = jalali_mktime(23, 59, 59, $month, $gday2, $year); + $te = persian_mktime(23, 59, 59, $month, $gday2, $year); $date = serendipity_formatTime('%B %Y', $ts, false); } } diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index c2dbcf7..9f29466 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -109,7 +109,7 @@ $serendipity['languages'] = array('en' => 'English', /* Available Calendars */ $serendipity['calendars'] = array('gregorian' => 'Gregorian', - 'jalali-utf8' => 'Jalali (utf8)'); + 'persian-utf8' => 'Persian (utf8)'); /* * Load main language file