/**
* 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
* @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'); }
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);