function Days($yFrom, $mFrom, $dFrom, $yTo, $mTo, $dTo) { $iDays = 0; for ($i = $yFrom; $i < $yTo; $i++) { $iDays += DayOfYear($i); } for ($i = 1; $i < $mFrom; $i++) { $iDays -= DayOfMonth($yFrom, $i); } for ($i = 1; $i < $mTo; $i++) { $iDays += DayOfMonth($yTo, $i); } return $iDays + $dTo - $dFrom; }
function pstrftime($format, $timestamp = "") { global $pdateMonthName, $pdateWeekName, $MonthDays; if ($timestamp === "") { $timestamp = time(); } // Create need date parametrs $date = date("Y-m-d-w", $timestamp); list($gYear, $gMonth, $gDay, $gWeek) = explode('-', $date); list($pYear, $pMonth, $pDay) = gregorian_to_jalali($gYear, $gMonth, $gDay); $pWeek = $gWeek + 1; if ($pWeek == 7) { $pWeek = 0; } $lenghFormat = strlen($format); $i = 0; $result = ""; while ($i < $lenghFormat) { $par = $format[$i]; if ($par == "%") { $type = $format[++$i]; switch ($type) { //Day case 'a': $result .= substr($pdateWeekName[$pWeek], 0, 2); break; case 'A': $result .= $pdateWeekName[$pWeek]; break; case 'd': $result .= $pDay < 10 ? "0" . $pDay : $pDay; break; case 'e': $result .= $pDay; break; case 'j': $dayinM = DayOfYear($pYear, $pMonth, $pDay); $result .= $dayinM < 10 ? "00" . $dayinM : ($dayinM < 100 ? "0" . $dayinM : $dayinM); break; case 'u': $result .= $pWeek + 1; break; case 'w': $result .= $pWeek; break; //Week //Week case 'U': $result .= floor(DayOfYear($pYear, $pMonth, $pDay) / 7); break; case 'V': case 'W': $result .= ceil(DayOfYear($pYear, $pMonth, $pDay) / 7); break; //Month //Month case 'b': case 'h': $result .= substr($pdateMonthName[$pMonth], 0, 6); break; case 'B': $result .= $pdateMonthName[$pMonth]; break; case 'm': $result .= $pMonth < 10 ? "0" . $pMonth : $pMonth; break; //Year //Year case 'C': $result .= ceil($pYear / 100); break; case 'g': case 'y': $result .= substr($pYear, 2); break; case 'G': case 'Y': $result .= $pYear; break; //Time //Time case 'H': case 'I': case 'l': case 'M': case 'R': case 'S': case 'T': case 'X': case 'z': case 'Z': $result .= strftime("%" . $type, $timestamp); break; case 'p': case 'P': case 'r': if (date('a', $timestamp) == 'am') { $result .= $type == 'p' ? 'ق.ظ' : ($type == 'P' ? 'قبل از ظهر' : strftime("%I:%M:%S قبل از ظهر", $timestamp)); } else { $result .= $type == 'p' ? 'ب.ظ' : ($type == 'P' ? 'بعد از ظهر' : strftime("%I:%M:%S بعد از ظهر", $timestamp)); } break; //Time and Date Stamps //Time and Date Stamps case 'c': $result .= substr($pdateWeekName[$pWeek], 0, 2) . " " . substr($pdateMonthName[$pMonth], 0, 6) . " " . $pDay . " " . strftime("%T", $timestamp) . " " . $pYear; break; case 'D': case 'x': $result .= ($pMonth < 10 ? "0" . $pMonth : $pMonth) . "/" . ($pDay < 10 ? "0" . $pDay : $pDay) . "/" . substr($pYear, 2); break; case 'F': $result .= $pYear . "-" . ($pMonth < 10 ? "0" . $pMonth : $pMonth) . "-" . ($pDay < 10 ? "0" . $pDay : $pDay); break; case 's': $result .= $timestamp; break; //Miscellaneous //Miscellaneous case 'n': $result .= "\n"; break; case 't': $result .= "\t"; break; case '%': $result .= "%"; break; default: $result .= "%" . $type; } } else { $result .= $par; } $i++; } return $result; }
function pstrftime($format, $timestamp = NULL) { global $pdate_month_name, $pdate_week_name, $pdate_month_days; if (!$timestamp) { $timestamp = time(); } # Create need date parametrs list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp)); list($pYear, $pMonth, $pDay) = gregorian_to_jalali($gYear, $gMonth, $gDay); $pWeek = $gWeek + 1; if ($pWeek >= 7) { $pWeek = 0; } $lenghFormat = strlen($format); $i = 0; $result = ''; while ($i < $lenghFormat) { $par = $format[$i]; if ($par == '%') { $type = $format[++$i]; switch ($type) { # Day case 'a': $result .= substr($pdate_week_name[$pWeek], 0, 2); break; case 'A': $result .= $pdate_week_name[$pWeek]; break; case 'd': $result .= $pDay < 10 ? '0' . $pDay : $pDay; break; case 'e': $result .= $pDay; break; case 'j': $dayinM = DayOfYear($pMonth, $pDay); $result .= $dayinM < 10 ? '00' . $dayinM : $dayinM < 100 ? '0' . $dayinM : $dayinM; break; case 'u': $result .= $pWeek + 1; break; case 'w': $result .= $pWeek; break; # Week # Week case 'U': $result .= floor(DayOfYear($pMonth, $pDay) / 7); break; case 'V': case 'W': $result .= ceil(DayOfYear($pMonth, $pDay) / 7); break; # Month # Month case 'b': case 'h': $result .= substr($pdate_month_name[$pMonth], 0, 6); break; case 'B': $result .= $pdate_month_name[$pMonth]; break; case 'm': $result .= $pMonth < 10 ? '0' . $pMonth : $pMonth; break; # Year # Year case 'C': $result .= ceil($pYear / 100); break; case 'g': case 'y': $result .= substr($pYear, 2); break; case 'G': case 'Y': $result .= $pYear; break; # Time # Time case 'H': case 'I': case 'l': case 'M': case 'R': case 'S': case 'T': case 'X': case 'z': case 'Z': $result .= strftime('%' . $type, $timestamp); break; case 'p': case 'P': case 'r': if (date('a', $timestamp) == 'am') { $result .= $type == 'p' ? 'ق.ظ' : $type == 'P' ? 'قبل از ظهر' : strftime("%I:%M:%S قبل از ظهر", $timestamp); } else { $result .= $type == 'p' ? 'ب.ظ' : $type == 'P' ? 'بعد از ظهر' : strftime("%I:%M:%S بعد از ظهر", $timestamp); } break; # Time and Date Stamps # Time and Date Stamps case 'c': $result .= substr($pdate_week_name[$pWeek], 0, 2) . ' ' . substr($pdate_month_name[$pMonth], 0, 6) . ' ' . $pDay . ' ' . strftime("%T", $timestamp) . ' ' . $pYear; break; case 'D': case 'x': $result .= ($pMonth < 10 ? '0' . $pMonth : $pMonth) . '-' . ($pDay < 10 ? '0' . $pDay : $pDay) . '-' . substr($pYear, 2); break; case 'F': $result .= $pYear . '-' . ($pMonth < 10 ? '0' . $pMonth : $pMonth) . '-' . ($pDay < 10 ? '0' . $pDay : $pDay); break; case 's': $result .= $timestamp; break; # Miscellaneous # Miscellaneous case 'n': $result .= "\n"; break; case 't': $result .= "\t"; break; case '%': $result .= '%'; break; default: $result .= '%' . $type; } } else { $result .= $par; } $i++; } return $result; }