|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Helpers;
|
|
|
|
|
class TDate
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# variables #
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Parsi date variables
|
|
|
|
|
*/
|
|
|
|
|
private $persian_month_names = ['', 'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'];
|
|
|
|
|
private $persian_short_month_names = ['', 'فرو', 'ارد', 'خرد', 'تیر', 'مرد', 'شهر', 'مهر', 'آبا', 'آذر', 'دی', 'بهم', 'اسف'];
|
|
|
|
|
private $sesson = ['بهار', 'تابستان', 'پاییز', 'زمستان'];
|
|
|
|
|
private $persian_day_names = ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'];
|
|
|
|
|
private $persian_day_small = ["ی", "د", "س", "چ", "پ", "ج", "ش"];
|
|
|
|
|
private $j_days_in_month = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30];
|
|
|
|
|
private $j_days_sum_month = [0, 0, 31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336];
|
|
|
|
|
private $g_days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
|
|
|
private $g_days_leap_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
|
|
|
private $g_days_sum_month = [0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* hijridate varibles
|
|
|
|
|
* modifed from Islamic Hijri Date Time Class by: Abdulrhman Alkhodiry
|
|
|
|
|
*/
|
|
|
|
|
private $jdl = [8761, 8790, 8820, 8849, 8879, 8908, 8937, 8967, 8996, 9026, 9055, 9085, 9115, 9144, 9174, 9204, 9233, 9263, 9292, 9321, 9351, 9380, 9409, 9439, 9469, 9498, 9528, 9558, 9588, 9617, 9647, 9676, 9705, 9735, 9764, 9793, 9823, 9852, 9882, 9912, 9942, 9971, 10001, 10031, 10060, 10089, 10119, 10148, 10177, 10207, 10236, 10266, 10296, 10325, 10355, 10385, 10414, 10444, 10473, 10503, 10532, 10561, 10591, 10620, 10650, 10679, 10709, 10739, 10769, 10798, 10828, 10857, 10887, 10916, 10946, 10975, 11004, 11034, 11063, 11093, 11123, 11152, 11182, 11211, 11241, 11271, 11300, 11330, 11359, 11389, 11418, 11447, 11477, 11506, 11536, 11566, 11595, 11625, 11654, 11684, 11714, 11743, 11773, 11802, 11831, 11861, 11890, 11920, 11949, 11979, 12009, 12038, 12068, 12098, 12127, 12157, 12186, 12215, 12245, 12274, 12303, 12333, 12363, 12392, 12422, 12452, 12482, 12511, 12541, 12570, 12599, 12629, 12658, 12687, 12717, 12746, 12776, 12806, 12836, 12865, 12895, 12925, 12954, 12983, 13013, 13042, 13071, 13101, 13130, 13160, 13190, 13219, 13249, 13279, 13309, 13338, 13367, 13397, 13426, 13455, 13485, 13514, 13544, 13573, 13603, 13633, 13663, 13692, 13722, 13751, 13781, 13810, 13839, 13869, 13898, 13928, 13957, 13987, 14017, 14046, 14076, 14106, 14135, 14165, 14194, 14223, 14253, 14282, 14312, 14341, 14371, 14400, 14430, 14460, 14489, 14519, 14549, 14578, 14608, 14637, 14666, 14696, 14725, 14755, 14784, 14814, 14843, 14873, 14903, 14932, 14962, 14992, 15021, 15051, 15080, 15109, 15139, 15168, 15198, 15227, 15257, 15286, 15316, 15346, 15376, 15405, 15435, 15464, 15493, 15523, 15552, 15581, 15611, 15640, 15670, 15700, 15730, 15759, 15789, 15819, 15848, 15877, 15907, 15936, 15965, 15995, 16024, 16054, 16084, 16113, 16143, 16173, 16203, 16232, 16261, 16291, 16320, 16349, 16379, 16408, 16438, 16467, 16497, 16527, 16557, 16586, 16616, 16645, 16675, 16704, 16733, 16763, 16792, 16822, 16851, 16881, 16911, 16940, 16970, 17000, 17029, 17059, 17088, 17117, 17147, 17176, 17206, 17235, 17265, 17294, 17324, 17354, 17383, 17413, 17443, 17472, 17501, 17531, 17560, 17590, 17619, 17649, 17678, 17708, 17737, 17767, 17797, 17826, 17856, 17885, 17915, 17944, 17974, 18003, 18033, 18062, 18092, 18121, 18151, 18180, 18210, 18240, 18269, 18299, 18329, 18358, 18387, 18417, 18446, 18475, 18505, 18534, 18564, 18594, 18624, 18653, 18683, 18713, 18742, 18771, 18801, 18830, 18859, 18889, 18918, 18948, 18978, 19007, 19037, 19067, 19097, 19126, 19155, 19185, 19214, 19243, 19273, 19302, 19332, 19361, 19391, 19421, 19451, 19480, 19510, 19539, 19569, 19598, 19627, 19657, 19686, 19716, 19745, 19775, 19805, 19835, 19864, 19894, 19923, 19953, 19982, 20011, 20041, 20070, 20100, 20129, 20159, 20188, 20218, 20248, 20278, 20307, 20337, 20366, 20395, 20425, 20454, 20484, 20513, 20543, 20572, 20602, 20632, 20661, 20691, 20720, 20750, 20779, 20809, 20838, 20868, 20897, 20927, 20956, 20986, 21015, 21045, 21075, 21104, 21134, 21163, 21193, 21222, 21252, 21281, 21311, 21340, 21370, 21399, 21429, 21458, 21488, 21518, 21547, 21577, 21606, 21636, 21665, 21695, 21724, 21753, 21783, 21812, 21842, 21872, 21901, 21931, 21961, 21990, 22020, 22049, 22079, 22108, 22137, 22167, 22196, 22226, 22255, 22285, 22315, 22345, 22374, 22404, 22433, 22463, 22492, 22521, 22551, 22580, 22610, 22639, 22669, 22699, 22729, 22758, 22788, 22817, 22847, 22876, 22905, 22935, 22964, 22994, 23023, 23053, 23083, 23112, 23142, 23172, 23201, 23231, 23260, 23289, 23319, 23348, 23378, 23407, 23437, 23466, 23496, 23526, 23555, 23585, 23614, 23644, 23673, 23703, 23732, 23762, 23791, 23821, 23850, 23880, 23909, 23939, 23969, 23998, 24028, 24057, 24087, 24116, 24146, 24175, 24205, 24234, 24264, 24293, 24323, 24352, 24382, 24412, 24441, 24471, 24500, 24530, 24559, 24589, 24618, 24647, 24677, 24706, 24736, 24766, 24795, 24825, 24855, 24884, 24914, 24943, 24973, 25002, 25031, 25061, 25090, 25120, 25149, 25179, 25209, 25239, 25268, 25298, 25327, 25357, 25386, 25415, 25445, 25474, 25504, 25533, 25563, 25593, 25623, 25652, 25682, 25711, 25741, 25770, 25799, 25829, 25858, 25887, 25917, 25947, 25977, 26006, 26036, 26066, 26095, 2
|
|
|
|
|
public $a = ["ar" => ["am" => "ص", "pm" => "م"]];
|
|
|
|
|
public $A = ["ar" => ["AM" => "صباحاً", "PM" => "مساءً"]];
|
|
|
|
|
protected static $instance;
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# general functions #
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
public static function GetInstance()
|
|
|
|
|
{
|
|
|
|
|
if (!isset(self::$instance)) {
|
|
|
|
|
self::$instance = new self();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# main functions #
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* usual gregurian date
|
|
|
|
|
* @param string $format
|
|
|
|
|
* @param timestamp $time_stamp
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function Date($format, $time_stamp = 'now')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
$time_stamp = $this->_makeTime($time_stamp);
|
|
|
|
|
|
|
|
|
|
$result = date($format, $time_stamp);
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* relative date
|
|
|
|
|
* @param string $time
|
|
|
|
|
* @return string
|
|
|
|
|
* @test need to translate
|
|
|
|
|
*/
|
|
|
|
|
public function RDate($time = 'now')
|
|
|
|
|
{
|
|
|
|
|
$format = 'd m Y H:i';
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
$time = $this->_makeTime($time);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$delta = time() - $time;
|
|
|
|
|
|
|
|
|
|
if ($delta < 1 * MINUTE) {
|
|
|
|
|
return $delta == 1 ? __("one second ago") : $delta . __(" seconds ago");
|
|
|
|
|
}
|
|
|
|
|
if ($delta < 2 * MINUTE) {
|
|
|
|
|
return __("a minute ago");
|
|
|
|
|
}
|
|
|
|
|
if ($delta < 45 * MINUTE) {
|
|
|
|
|
return floor($delta / MINUTE) . __(" minutes ago");
|
|
|
|
|
}
|
|
|
|
|
if ($delta < 90 * MINUTE) {
|
|
|
|
|
return __("an hour ago");
|
|
|
|
|
}
|
|
|
|
|
if ($delta < 24 * HOUR) {
|
|
|
|
|
return floor($delta / HOUR) . __(" hours ago");
|
|
|
|
|
}
|
|
|
|
|
if ($delta < 48 * HOUR) {
|
|
|
|
|
return __("yesterday");
|
|
|
|
|
}
|
|
|
|
|
if ($delta < 30 * DAY) {
|
|
|
|
|
return floor($delta / DAY) . __(" days ago");
|
|
|
|
|
} else {
|
|
|
|
|
return $this->PDate($format, $time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Persian Date
|
|
|
|
|
* @param string $format
|
|
|
|
|
* @param string $time
|
|
|
|
|
* @param string 'ar' number langs
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function PDate($format, $time = "now")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
$time_stamp = $this->_makeTime($time);
|
|
|
|
|
|
|
|
|
|
$date = getdate($time_stamp);
|
|
|
|
|
|
|
|
|
|
$j_days_in_month = [31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336, 365];
|
|
|
|
|
list($date['year'], $date['mon'], $date['mday']) = self::Ge2Parsi($date['year'], $date['mon'], $date['mday']);
|
|
|
|
|
|
|
|
|
|
$out = '';
|
|
|
|
|
for ($i = 0; $i < strlen($format); $i++) {
|
|
|
|
|
switch ($format[$i]) {
|
|
|
|
|
//day
|
|
|
|
|
case 'd':
|
|
|
|
|
$out .= (strlen($date['mday']) == 1) ? '0' . $date['mday'] : $date['mday'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'D':
|
|
|
|
|
$out .= $this->persian_day_small[(int)$date['wday']];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'l':
|
|
|
|
|
$out .= $this->persian_day_names[(int)$date['wday']];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'j':
|
|
|
|
|
$out .= $date['mday'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'N':
|
|
|
|
|
$out .= $date['mday'] + 1;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'w':
|
|
|
|
|
$x = date('w', $time_stamp) + 1;
|
|
|
|
|
if ($x == 7) {
|
|
|
|
|
$x = 0;
|
|
|
|
|
}
|
|
|
|
|
$out .= $x;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'z':
|
|
|
|
|
$mmm = (int)$date['mon'];
|
|
|
|
|
if ($mmm < 8) {
|
|
|
|
|
$mmm--;
|
|
|
|
|
$o = ($mmm * 31) + $date['mday'];
|
|
|
|
|
} elseif ($mmm == 12) {
|
|
|
|
|
$o = 336 + $date['mday'];
|
|
|
|
|
} else {
|
|
|
|
|
$mmm -= 6;
|
|
|
|
|
$o = ($mmm * 30) + $date['mday'] + 186;
|
|
|
|
|
}
|
|
|
|
|
$out .= $o;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//week
|
|
|
|
|
case'W':
|
|
|
|
|
$yday = $this->j_days_sum_month[(int)($date['mon'] - 1)] + $date['mday'];
|
|
|
|
|
$out .= ((int)$yday / 7);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//month
|
|
|
|
|
case'f':
|
|
|
|
|
$mon = $date['mon'];
|
|
|
|
|
switch ($mon) {
|
|
|
|
|
case($mon < 4):
|
|
|
|
|
$out .= $this->sesson[0];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case($mon < 7):
|
|
|
|
|
$out .= $this->sesson[1];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case($mon < 10):
|
|
|
|
|
$out .= $this->sesson[2];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case($mon > 9):
|
|
|
|
|
$out .= $this->sesson[3];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'F':
|
|
|
|
|
$out .= $this->persian_month_names[((int)$date['mon'])];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'm':
|
|
|
|
|
$out .= (strlen($date['mon']) == 1) ? '0' . $date['mon'] : $date['mon'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'M':
|
|
|
|
|
$out .= $this->persian_short_month_names[((int)$date['mon'])];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'n':
|
|
|
|
|
$out .= $date['mon'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'S':
|
|
|
|
|
$out .= 'ام';
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case't':
|
|
|
|
|
$out .= $this->j_days_in_month[((int)$date['mon'])];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//year
|
|
|
|
|
case'L':
|
|
|
|
|
$out .= (($date['year'] % 4) == 0) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'o':
|
|
|
|
|
case'Y':
|
|
|
|
|
$out .= $date['year'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'y':
|
|
|
|
|
$out .= substr($date['year'], 2, 2);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//time
|
|
|
|
|
case'a':
|
|
|
|
|
$out .= ($date['hours'] < 12) ? 'ق.ظ' : 'ب.ظ';
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'A':
|
|
|
|
|
$out .= ($date['hours'] < 12) ? 'قبل از ظهر' : 'بعد از ظهر';
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'B':
|
|
|
|
|
$out .= (int)(1 + ($date['mon'] / 3));
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'g':
|
|
|
|
|
$out .= ($date['hours'] > 12) ? $date['hours'] - 12 : $date['hours'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'G':
|
|
|
|
|
$out .= $date['hours'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'h':
|
|
|
|
|
$hour = ($date['hours'] > 12) ? $date['hours'] - 12 : $date['hours'];
|
|
|
|
|
$out .= ($hour < 10) ? "0$hour" : $hour;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'H':
|
|
|
|
|
$out .= (strlen($date['hours']) == 1) ? '0' . $date['hours'] : $date['hours'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'i':
|
|
|
|
|
$out .= (strlen($date['minutes']) == 1) ? '0' . $date['minutes'] : $date['minutes'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case's':
|
|
|
|
|
$out .= (strlen($date['seconds']) == 1) ? '0' . $date['seconds'] : $date['seconds'];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//full date time
|
|
|
|
|
case'c':
|
|
|
|
|
$out = $date['year'] . '/' . $date['mon'] . '/' . $date['mday'] . ' ' . $date['hours'] . ':' . (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':' . (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']); //2004-02-12T15:19:21+00:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'r':
|
|
|
|
|
$out = $this->persian_day_names[(int)$date['wday']] . ',' . $date['mday'] . ' ' . $this->persian_month_names[((int)$date['mon'])] . ' ' . $date['year'] . ' ' . $date['hours'] . ':' . (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':' . (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']); //Thu, 21 Dec 2000 16:01:07
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case'U':
|
|
|
|
|
$out = $time_stamp;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
//others
|
|
|
|
|
case'e':
|
|
|
|
|
case'I':
|
|
|
|
|
case'O':
|
|
|
|
|
case'P':
|
|
|
|
|
case'T':
|
|
|
|
|
case'Z':
|
|
|
|
|
case'u':
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$out .= $format[$i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $out;
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private function _ard_int($float) {
|
|
|
|
|
// return ($float < -0.0000001) ? ceil($float - 0.0000001) : floor($float + 0.0000001);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic date
|
|
|
|
|
* @param string $format
|
|
|
|
|
* @param string $time_stamp
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function ADate($format, $time_stamp = "now")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$time_stamp = $this->_makeTime($time_stamp);
|
|
|
|
|
$result = $this->_arabicDate('ar:' . $format, $time_stamp);
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Islamic hijri ghamari date
|
|
|
|
|
* returns a string formatted according to the given format string using the given
|
|
|
|
|
* integer timestamp or the current time if no timestamp is given. In other words, timestamp
|
|
|
|
|
* is optional and defaults to the value of time().
|
|
|
|
|
*
|
|
|
|
|
* @param $format String date format (see http://php.net/manual/en/function.date.php)
|
|
|
|
|
* @param $time_stamp Integer time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
|
|
|
|
|
*
|
|
|
|
|
* @return String Returns the Hijri islamic date according to format and timestamp in Arabic/English
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function IDate($format, $time_stamp = 'now')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$time_stamp = $this->_makeTime($time_stamp);
|
|
|
|
|
|
|
|
|
|
list($d, $D, $j, $l, $S, $F, $m, $M, $n, $t, $L, $o, $Y, $y, $w, $a, $A, $H, $i, $s, $O) = explode("/", date("d/D/j/l/S/F/m/M/n/t/L/o/Y/y/w/a/A/H/i/s/O", $time_stamp));
|
|
|
|
|
extract($this->Ge2Ism($d, $m, $Y));
|
|
|
|
|
$j = $day;
|
|
|
|
|
$t = $ml;
|
|
|
|
|
$L = $ln;
|
|
|
|
|
$d = sprintf("%02d", $day);
|
|
|
|
|
$m = sprintf("%02d", $month);
|
|
|
|
|
$n = $month;
|
|
|
|
|
$Y = $year;
|
|
|
|
|
$y = substr($year, 2);
|
|
|
|
|
$S = substr($j, -1) == 1 ? "st" : (substr($j, -1) == 2 ? "nd" : (substr($j, -1) == 3 ? "rd" : "th"));
|
|
|
|
|
$F = $this->_getIslamicMonthName($n);
|
|
|
|
|
$M = $this->_getIslamicMonthName($n, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$D = $this->_getIslamicDayName($w, true);
|
|
|
|
|
$l = $this->_getIslamicDayName($w);
|
|
|
|
|
if ('ar' == "ar") {
|
|
|
|
|
$S = "";
|
|
|
|
|
$a = $this->a['ar'][$a];
|
|
|
|
|
$A = $this->A['ar'][$A];
|
|
|
|
|
}
|
|
|
|
|
$r = "$D, $j $M $Y $H:$i:$s $O";
|
|
|
|
|
$davars = ["d", "D", "j", "l", "S", "F", "m", "M", "n", "t", "L", "o", "Y", "y", "a", "A", "r"];
|
|
|
|
|
$myvars = [$d, "¢", $j, "£", "ç", "¥", $m, "©", $n, $t, $L, $Y, $Y, $y, "ï", "â", "®"];
|
|
|
|
|
$format = str_replace($davars, $myvars, $format);
|
|
|
|
|
$date = date($format, $time_stamp);
|
|
|
|
|
$date = str_replace(["¢", "£", "ç", "¥", "©", "ï", "â", "®"], [$D, $l, $S, $F, $M, $a, $A, $r], $date);
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns True if is an islamic Leap Year
|
|
|
|
|
* @param $ayear : a year !==0.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function IslamicLeapYear($year)
|
|
|
|
|
{
|
|
|
|
|
if ((((11 * $year) + 14) % 30) < 11) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* is leap year
|
|
|
|
|
* @param int $year
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private function IsLeapYear($year)
|
|
|
|
|
{
|
|
|
|
|
if ((($year % 4) == 0 && ($year % 100) != 0) || (($year % 400) == 0) && ($year % 100) == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# private functions #
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* make timestamp and add offset to it.
|
|
|
|
|
* @param string|timestamp $time
|
|
|
|
|
* @return timestamp
|
|
|
|
|
*/
|
|
|
|
|
private function _makeTime($time)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// pre hook
|
|
|
|
|
|
|
|
|
|
$time_stamp = is_numeric($time) && (int)$time == $time ? $time : strtotime($time);
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $time_stamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* returns the month full name or shorting version
|
|
|
|
|
* @param Integer $month the month number
|
|
|
|
|
* @param Boolean $shorten defualt false
|
|
|
|
|
* @return String Month name
|
|
|
|
|
*/
|
|
|
|
|
private function _getIslamicMonthName($month, $shorten = false)
|
|
|
|
|
{
|
|
|
|
|
$longMonth = ["en" => [1 => "Muharram", "Safar", "Rabi' I", "Rabi' II", "Jumada I", "Jumada II", "Rajab", "Sha'aban", "Ramadan", "Shawwal", "Dhu al-Qi'dah", "Dhu al-Hijjah"], "ar" => [1 => "محرّم", "صفر", "ربيع الأول", "ربيع الآخر", "جمادى الأول", "جمادى الآخر", "رجب", "شعبان", "رمضان", "شوّال", "ذو القعدة", "ذو الحجة"]];
|
|
|
|
|
$shortMonth = ["en" => [1 => "Muh", "Saf", "Rb1", "Rb2", "Jm1", "Jm2", "Raj", "Shb", "Rmd", "Shw", "DhQ", "DhH"], "ar" => [1 => "مح", "صف", "ر1", "ر2", "ج1", "ج2", "رج", "شع", "رم", "شو", "ذق", "ذح"]];
|
|
|
|
|
$_lmonth = ($shorten) ? $shortMonth : $longMonth;
|
|
|
|
|
$ret = $_lmonth['ar'][$month];
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* returns the day full name or shorting version
|
|
|
|
|
* @param Integer $day the day number
|
|
|
|
|
* @param Boolean $shorten defualt false
|
|
|
|
|
* @return String Day name
|
|
|
|
|
*/
|
|
|
|
|
private function _getIslamicDayName($day, $shorten = false)
|
|
|
|
|
{
|
|
|
|
|
$daySingle = [
|
|
|
|
|
"en" => [1 => "Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"],
|
|
|
|
|
"ar" => [1 => "اثنين", "ثلاثاء", "أربعاء", "خميس", "جمعة", "سبت", "احد"],
|
|
|
|
|
];
|
|
|
|
|
$dayPlural = [
|
|
|
|
|
"en" => [1 => "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
|
|
|
|
"ar" => [1 => "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت", "الأحد",],
|
|
|
|
|
];
|
|
|
|
|
$_lmonth = ($shorten) ? $daySingle : $dayPlural;
|
|
|
|
|
if ($day == 0) {
|
|
|
|
|
$day++;
|
|
|
|
|
}
|
|
|
|
|
$ret = $_lmonth['ar'][$day];
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* make arabic and islamic date
|
|
|
|
|
* @param string $format
|
|
|
|
|
* @param timestamp $time_stamp
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function _arabicDate($format, $time_stamp)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
$format: [*]hj|ar|en:[jdl][Fmn][Yy][Aa] (php.date function handles the rest chars)
|
|
|
|
|
examples:
|
|
|
|
|
echo arabicDate('hj:l d-F-Y هـ', time());
|
|
|
|
|
echo arabicDate('ar:l d/F - h:iA', time());
|
|
|
|
|
*/
|
|
|
|
|
$format = trim($format);
|
|
|
|
|
if (substr($format, 0, 1) == '*') {
|
|
|
|
|
$use_span = true;
|
|
|
|
|
$format = substr($format, 1);
|
|
|
|
|
} else {
|
|
|
|
|
$use_span = false;
|
|
|
|
|
}
|
|
|
|
|
$type = substr($format, 0, 3);
|
|
|
|
|
|
|
|
|
|
$arDay = ["Sat" => "السبت", "Sun" => "الأحد", "Mon" => "الإثنين", "Tue" => "الثلاثاء",
|
|
|
|
|
"Wed" => "الأربعاء", "Thu" => "الخميس", "Fri" => "الجمعة",];
|
|
|
|
|
$ampm = ['am' => 'صباحا', 'pm' => 'مساء'];
|
|
|
|
|
list($d, $m, $y, $dayname, $monthname, $am) = explode(' ', date('d m Y D M a', $time_stamp));
|
|
|
|
|
|
|
|
|
|
if ($type == 'hj:') {
|
|
|
|
|
// if (($y > 1582) || (($y == 1582) && ($m > 10)) || (($y == 1582) && ($m == 10) && ($d > 14))) {
|
|
|
|
|
// $jd = $this->_ard_int((1461 * ($y + 4800 + $this->_ard_int(($m - 14) / 12))) / 4);
|
|
|
|
|
// $jd+=$this->_ard_int((367 * ($m - 2 - 12 * ($this->_ard_int(($m - 14) / 12)))) / 12);
|
|
|
|
|
// $jd-=$this->_ard_int((3 * ($this->_ard_int(($y + 4900 + $this->_ard_int(($m - 14) / 12)) / 100))) / 4);
|
|
|
|
|
// $jd+=$d - 32075;
|
|
|
|
|
// } else {
|
|
|
|
|
// $jd = 367 * $y - $this->_ard_int((7 * ($y + 5001 + $this->_ard_int(($m - 9) / 7))) / 4) + $this->_ard_int((275 * $m) / 9) + $d + 1729777;
|
|
|
|
|
// }
|
|
|
|
|
// $l = $jd - 1948440 + 10632;
|
|
|
|
|
// $n = $this->_ard_int(($l - 1) / 10631);
|
|
|
|
|
// $l = $l - 10631 * $n + 355; // Correction: 355 instead of 354
|
|
|
|
|
// $j = ($this->_ard_int((10985 - $l) / 5316)) * ($this->_ard_int((50 * $l) / 17719)) + ($this->_ard_int($l / 5670)) * ($this->_ard_int((43 * $l) / 15238));
|
|
|
|
|
// $l = $l - ($this->_ard_int((30 - $j) / 15)) * ($this->_ard_int((17719 * $j) / 50)) - ($this->_ard_int($j / 16)) * ($this->_ard_int((15238 * $j) / 43)) + 29;
|
|
|
|
|
// $m = $this->_ard_int((24 * $l) / 709);
|
|
|
|
|
// $d = $l - $this->_ard_int((709 * $m) / 24);
|
|
|
|
|
// $y = 30 * $n + $j - 30;
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// $format = substr($format, 3);
|
|
|
|
|
// $hjMonth = array("محرم", "صفر", "ربيع أول", "ربيع ثاني",
|
|
|
|
|
// "جماد أول", "جماد ثاني", "رجب", "شعبان", "رمضان", "شوال", "ذو القعدة", "ذو الحجة");
|
|
|
|
|
//
|
|
|
|
|
// $format = str_replace('j', $d, $format);
|
|
|
|
|
// $format = str_replace('d', str_pad($d, 2, 0, STR_PAD_LEFT), $format);
|
|
|
|
|
// $format = str_replace('l', $arDay[$dayname], $format);
|
|
|
|
|
// $format = str_replace('F', $hjMonth[$m - 1], $format);
|
|
|
|
|
// $format = str_replace('m', str_pad($m, 2, 0, STR_PAD_LEFT), $format);
|
|
|
|
|
// $format = str_replace('n', $m, $format);
|
|
|
|
|
// $format = str_replace('Y', $y, $format);
|
|
|
|
|
// $format = str_replace('y', substr($y, 2), $format);
|
|
|
|
|
// $format = str_replace('a', substr($ampm[$am], 0, 1), $format);
|
|
|
|
|
// $format = str_replace('A', $ampm[$am], $format);
|
|
|
|
|
} elseif ($type == 'ar:') {
|
|
|
|
|
$format = substr($format, 3);
|
|
|
|
|
$arMonth = ["Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "ابريل", "May" => "مايو",
|
|
|
|
|
"Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "اغسطس", "Sep" => "سبتمبر", "Oct" => "اكتوبر",
|
|
|
|
|
"Nov" => "نوفمبر", "Dec" => "ديسمبر",];
|
|
|
|
|
$format = str_replace('l', $arDay[$dayname], $format);
|
|
|
|
|
$format = str_replace('F', $arMonth[$monthname], $format);
|
|
|
|
|
$format = str_replace('a', substr($ampm[$am], 0, 1), $format);
|
|
|
|
|
$format = str_replace('A', $ampm[$am], $format);
|
|
|
|
|
}
|
|
|
|
|
$date = date($format, $time_stamp);
|
|
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* convert latin numbers to hindis
|
|
|
|
|
* @param string $num
|
|
|
|
|
* @param char $sp
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function _trimNumber($num, $sp = '٫')
|
|
|
|
|
{
|
|
|
|
|
$eng = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'];
|
|
|
|
|
$per = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', $sp];
|
|
|
|
|
$number = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
|
|
|
|
|
|
return empty($number) ? str_replace($per, $eng, $num) : str_replace($eng, $per, $num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian get month day count
|
|
|
|
|
* @param int $month
|
|
|
|
|
* @param int $year
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
private function _pGetMonthDayCount($month, $year = 0)
|
|
|
|
|
{
|
|
|
|
|
$month = (int)$month;
|
|
|
|
|
$year = (int)$year;
|
|
|
|
|
|
|
|
|
|
if ($month < 7) {
|
|
|
|
|
return 31;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Meher and after
|
|
|
|
|
if ($month != 12) {
|
|
|
|
|
$last_day = 30;
|
|
|
|
|
} elseif ($month == 12) {
|
|
|
|
|
$last_day = 29;
|
|
|
|
|
// 30 days espand
|
|
|
|
|
if ($this->IsLeapYear($year)) {
|
|
|
|
|
$last_day = 30;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $last_day;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# convert functions #
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse about any English textual datetime description into a Ism format
|
|
|
|
|
* if no format the date returned will be Ism d-m-Y
|
|
|
|
|
* @param String $strDate English textual datetime
|
|
|
|
|
* @param String $format The date format needed
|
|
|
|
|
* @param String $sep separator
|
|
|
|
|
* @return String Date in Ism as formated or like d-m-Y
|
|
|
|
|
*/
|
|
|
|
|
public function Str2Ism($strDate, $format = "d-m-Y")
|
|
|
|
|
{
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
if ($format == "d-m-Y") {
|
|
|
|
|
list($d, $m, $Y) = explode("/", date("d/m/Y", strtotime($strDate)));
|
|
|
|
|
extract($this->Ge2Ism($d, $m, $Y));
|
|
|
|
|
$date = "$day-$month-$year";
|
|
|
|
|
} else {
|
|
|
|
|
$date = $this->date($format, strtotime($strDate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an array of month, day, year, ln: which is "Islamic lunation number
|
|
|
|
|
* (Births of New Moons)", int: The length of current month.
|
|
|
|
|
*
|
|
|
|
|
* @param $day Integer Gregorian day of the month
|
|
|
|
|
* @param $month Integer Gregorian month number
|
|
|
|
|
* @param $year Integer Gregorian year in full (1999)
|
|
|
|
|
* @return Array Islamic hijri date[int month, int day, int year, int ln, int ml]
|
|
|
|
|
* @see Robert Gent method maker (http://www.phys.uu.nl/~vgent/islam/ummalqura.htm)
|
|
|
|
|
*/
|
|
|
|
|
public function Ge2Ism($day = 20, $month = 02, $year = 1976)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
$jd = GregorianToJD($month, $day, $year);
|
|
|
|
|
$mjd = $jd - 2400000;
|
|
|
|
|
foreach ($this->jdl as $i => $v) {
|
|
|
|
|
if ($v > ($mjd - 1)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$iln = $i + 15588; // Islamic lunation number (Births of New Moons)
|
|
|
|
|
$ii = floor(($i - 1) / 12);
|
|
|
|
|
$year = 1300 + $ii; // year
|
|
|
|
|
$month = $i - 12 * $ii; // month
|
|
|
|
|
$day = $mjd - $this->jdl[$i - 1]; //day
|
|
|
|
|
$ml = $this->jdl[$i] - $this->jdl[$i - 1]; // Month Length
|
|
|
|
|
list($_Date["month"], $_Date["day"], $_Date["year"], $_Date["ln"], $_Date["ml"]) = [$month, $day, $year, $iln, $ml];
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return ($_Date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Convert from Islamic date to Georgian date.
|
|
|
|
|
@param IYear a year !== 0
|
|
|
|
|
@param IMonth a month between 1 and 12
|
|
|
|
|
@param IDate a date between 1 and 31
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function Ism2Ge($IYear, $IMonth, $IDay)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
$y = $IYear;
|
|
|
|
|
$m = $IMonth;
|
|
|
|
|
$d = $IDay;
|
|
|
|
|
|
|
|
|
|
$jd = (int)((11 * $y + 3) / 30) + 354 * $y + 30 * $m - (int)(($m - 1) / 2) + $d + 1948440 - 385;
|
|
|
|
|
// $jd = (int)((11*$y+3)/30)+354*y+30*$m-(int)(($m-1)/2)+$d+1948440-385;
|
|
|
|
|
$this->julianday = $jd;
|
|
|
|
|
|
|
|
|
|
if ($jd > 2299160) {
|
|
|
|
|
$l = $jd + 68569;
|
|
|
|
|
$n = (int)((4 * $l) / 146097);
|
|
|
|
|
$l = $l - (int)((146097 * $n + 3) / 4);
|
|
|
|
|
$i = (int)((4000 * ($l + 1)) / 1461001);
|
|
|
|
|
$l = $l - (int)((1461 * $i) / 4) + 31;
|
|
|
|
|
$j = (int)((80 * $l) / 2447);
|
|
|
|
|
$d = $l - (int)((2447 * $j) / 80);
|
|
|
|
|
$l = (int)($j / 11);
|
|
|
|
|
$m = $j + 2 - 12 * $l;
|
|
|
|
|
$y = 100 * ($n - 49) + $i + $l;
|
|
|
|
|
} else {
|
|
|
|
|
$j = $jd + 1402;
|
|
|
|
|
$k = (int)(($j - 1) / 1461);
|
|
|
|
|
$l = $j - 1461 * $k;
|
|
|
|
|
$n = (int)(($l - 1) / 365) - (int)($l / 1461);
|
|
|
|
|
$i = $l - 365 * $n + 30;
|
|
|
|
|
$j = (int)((80 * $i) / 2447);
|
|
|
|
|
$d = $i - (int)((2447 * $j) / 80);
|
|
|
|
|
$i = (int)($j / 11);
|
|
|
|
|
$m = $j + 2 - 12 * $i;
|
|
|
|
|
$y = 4 * $k + $n + $i - 4716;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$date_g[2] = $d;
|
|
|
|
|
$date_g[1] = $m;
|
|
|
|
|
$date_g[0] = $y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $date_g;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Persian date to Gregorian
|
|
|
|
|
* @param int $jy year
|
|
|
|
|
* @param int $jm month 1-12
|
|
|
|
|
* @param int $jd day 1-31
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function Parsi2Ge($jy, $jm, $jd)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
$gd = ($jm - 2 > -1 ? $this->j_days_sum_month[((int)$jm)] + $jd : $jd);
|
|
|
|
|
$gy = $jy + 621;
|
|
|
|
|
if ($gd > 286) {
|
|
|
|
|
$gy++;
|
|
|
|
|
}
|
|
|
|
|
if (self::IsLeapYear($gy - 1) && 286 < $gd) {
|
|
|
|
|
$gd--;
|
|
|
|
|
}
|
|
|
|
|
if ($gd > 286) {
|
|
|
|
|
$gd -= 286;
|
|
|
|
|
} else {
|
|
|
|
|
$gd += 79;
|
|
|
|
|
}
|
|
|
|
|
if (self::IsLeapYear($gy)) {
|
|
|
|
|
for ($gm = 0; $gd > $this->g_days_leap_month[$gm]; $gm++) {
|
|
|
|
|
$gd -= $this->g_days_leap_month[$gm];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for ($gm = 0; $gd > $this->g_days_in_month[$gm]; $gm++) {
|
|
|
|
|
$gd -= $this->g_days_in_month[$gm];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$gm++;
|
|
|
|
|
|
|
|
|
|
$result = [$gy, $gm, $gd];
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gregorian date to Persian date
|
|
|
|
|
* @param int $gy year
|
|
|
|
|
* @param int $gm month 1-12
|
|
|
|
|
* @param int $gd day 1-31
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function Ge2Parsi($gy, $gm, $gd)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
$dayofyear = $this->g_days_sum_month[$gm] + $gd;
|
|
|
|
|
if (self::IsLeapYear($gy) and $gm > 2) {
|
|
|
|
|
$dayofyear++;
|
|
|
|
|
}
|
|
|
|
|
$d_33 = (int)((($gy - 16) % 132) * 0.0305);
|
|
|
|
|
$leap = $gy % 4;
|
|
|
|
|
$a = (($d_33 == 1 or $d_33 == 2) and ($d_33 == $leap or $leap == 1)) ? 78 : (($d_33 == 3 and $leap == 0) ? 80 : 79);
|
|
|
|
|
$b = ($d_33 == 3 or $d_33 < ($leap - 1) or $leap == 0) ? 286 : 287;
|
|
|
|
|
if ((int)(($gy - 10) / 63) == 30) {
|
|
|
|
|
$b--;
|
|
|
|
|
$a++;
|
|
|
|
|
}
|
|
|
|
|
if ($dayofyear > $a) {
|
|
|
|
|
$jy = $gy - 621;
|
|
|
|
|
$jd = $dayofyear - $a;
|
|
|
|
|
} else {
|
|
|
|
|
$jy = $gy - 622;
|
|
|
|
|
$jd = $dayofyear + $b;
|
|
|
|
|
}
|
|
|
|
|
for ($i = 0; $i < 11 and $jd > $this->j_days_in_month[$i]; $i++) {
|
|
|
|
|
$jd -= $this->j_days_in_month[$i];
|
|
|
|
|
}
|
|
|
|
|
$jm = ++$i;
|
|
|
|
|
|
|
|
|
|
$result = [$jy, strlen($jm) == 1 ? "0$jm" : $jm, strlen($jd) == 1 ? "0$jd" : $jd];
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian date to time stamp
|
|
|
|
|
* @param string $date date
|
|
|
|
|
* @param string $time time clock
|
|
|
|
|
* @return type
|
|
|
|
|
*/
|
|
|
|
|
public function Parsi2Timestamp($date = null, $time = '00:00:00')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
if ($date != null) {
|
|
|
|
|
list($jy, $jm, $jd) = explode('/', $date);
|
|
|
|
|
} else {
|
|
|
|
|
list($jy, $jm, $jd) = [0, 0, 0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arr = $this->Parsi2Ge($jy, $jm, $jd);
|
|
|
|
|
$result = strtotime($arr[0] . '/' . $arr[1] . '/' . $arr[2] . ' ' . $time);
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* hijri date to time stamp
|
|
|
|
|
* @param string $date date
|
|
|
|
|
* @param string $time time clock
|
|
|
|
|
* @return type
|
|
|
|
|
*/
|
|
|
|
|
public function Ism2Timestamp($date = null, $time = '00:00:00')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pre hook
|
|
|
|
|
|
|
|
|
|
if ($date != null) {
|
|
|
|
|
list($jy, $jm, $jd) = explode('/', $date);
|
|
|
|
|
} else {
|
|
|
|
|
list($jy, $jm, $jd) = [0, 0, 0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arr = $this->Ism2Ge($jy, $jm, $jd);
|
|
|
|
|
$result = strtotime($arr[0] . '/' . $arr[1] . '/' . $arr[2] . ' ' . $time);
|
|
|
|
|
|
|
|
|
|
// result hook
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
# interval functions #
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get time stamp gregorian system
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian strat today
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function Today()
|
|
|
|
|
{
|
|
|
|
|
return strtotime('today');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian strat yesterday
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function Yesterday()
|
|
|
|
|
{
|
|
|
|
|
return strtotime('yesterday');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian this week start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ThisWeekStart()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('this week 00:00:00'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian this week end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ThisWeekEnd()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('next week 00:00:00')) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian last week start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function LastWeekStart()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('last week 00:00:00'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian last week end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function LastWeekEnd()
|
|
|
|
|
{
|
|
|
|
|
return ($this->ThisWeekStart() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian this month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ThisMonthStart()
|
|
|
|
|
{
|
|
|
|
|
return mktime(0, 0, 0, date("n"), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian this month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ThisMonthEnd()
|
|
|
|
|
{
|
|
|
|
|
return mktime(23, 59, 59, date("n"), date("t"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian last month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function LastMonthStart()
|
|
|
|
|
{
|
|
|
|
|
return mktime(0, 0, 0, date("n", strtotime('last month')), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian last month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function LastMonthEnd()
|
|
|
|
|
{
|
|
|
|
|
return $this->ThisMonthStart() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian this year start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ThisYearStart()
|
|
|
|
|
{
|
|
|
|
|
return mktime(0, 0, 0, date("n", strtotime("first day of january " .
|
|
|
|
|
date('Y'))), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian this year end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ThisYearEnd()
|
|
|
|
|
{
|
|
|
|
|
return mktime(23, 59, 59, date("n", strtotime("last day of december " .
|
|
|
|
|
date('Y'))), date("n", strtotime("last day of december " .
|
|
|
|
|
date('t'))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian last year start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function LastYearStart()
|
|
|
|
|
{
|
|
|
|
|
return mktime(0, 0, 0, date("n", strtotime("first day of january " .
|
|
|
|
|
(date('Y') - 1))), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gregorian last year end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function LastYearEnd()
|
|
|
|
|
{
|
|
|
|
|
return mktime(23, 59, 59, date("n", strtotime("last day of december " .
|
|
|
|
|
(date('Y') - 1))), date("n", strtotime("last day of december "
|
|
|
|
|
. (date('Y') - 1))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
/**
|
|
|
|
|
* get time stamp arabic islamic system
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic strat today
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IToday()
|
|
|
|
|
{
|
|
|
|
|
return strtotime('today');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic strat yesterday
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IYesterday()
|
|
|
|
|
{
|
|
|
|
|
return strtotime('yesterday');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this week start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IThisWeekStart()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('last sat 00:00:00'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this week end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IThisWeekEnd()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('next sat 00:00:00')) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic last week start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ILastWeekStart()
|
|
|
|
|
{
|
|
|
|
|
return ($this->PThisWeekStart() - (86400 * 7));;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic last week end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ILastWeekEnd()
|
|
|
|
|
{
|
|
|
|
|
return ($this->PThisWeekStart() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IThisMonthStart()
|
|
|
|
|
{
|
|
|
|
|
$today = (int)$this->IDate('d');
|
|
|
|
|
$today--;
|
|
|
|
|
|
|
|
|
|
return $this->Today() - ($today * 86400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IThisMonthEnd()
|
|
|
|
|
{
|
|
|
|
|
$today = (int)$this->IDate('d', time() + (30 * 86400));
|
|
|
|
|
$today--;
|
|
|
|
|
|
|
|
|
|
return ($this->Today() + (30 * 86400)) - ($today * 86400) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic last month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ILastMonthStart()
|
|
|
|
|
{
|
|
|
|
|
$today = (int)$this->IDate('d', $this->ILastMonthEnd());
|
|
|
|
|
$today--;
|
|
|
|
|
|
|
|
|
|
return ($this->ILastMonthEnd() - ($today * 86400)) - 86399;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic last month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ILastMonthEnd()
|
|
|
|
|
{
|
|
|
|
|
return $this->IThisMonthStart() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this year start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IThisYearStart()
|
|
|
|
|
{
|
|
|
|
|
$past_day = $this->IDate('z', strtotime('yesterday'));
|
|
|
|
|
$result = strtotime('today') - (86400 * $past_day);
|
|
|
|
|
if ((int)$this->PDate('n') < 7) {
|
|
|
|
|
$result += 3600;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this year end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function IThisYearEnd()
|
|
|
|
|
{
|
|
|
|
|
if ($this->IslamicLeapYear((int)$this->IDate('Y'))) {
|
|
|
|
|
return $this->IThisYearStart() + (86400 * 355) - 1;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->IThisYearStart() + (86400 * 354) - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic last year start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ILastYearStart()
|
|
|
|
|
{
|
|
|
|
|
if ($this->IslamicLeapYear((int)$this->IDate('Y') - 1)) {
|
|
|
|
|
return $this->IThisYearStart() - (86400 * 354);
|
|
|
|
|
} else {
|
|
|
|
|
return $this->IThisYearStart() - (86400 * 353);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* arabic islamic this last year end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function ILastYearEnd()
|
|
|
|
|
{
|
|
|
|
|
return $this->IThisYearStart() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
/**
|
|
|
|
|
* get time stamp persian system
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian today start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PToday()
|
|
|
|
|
{
|
|
|
|
|
return strtotime('today');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian yesterday start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PYesterday()
|
|
|
|
|
{
|
|
|
|
|
return strtotime('yesterday');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this week start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisWeekStart()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('last sat 00:00:00'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this week end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisWeekEnd()
|
|
|
|
|
{
|
|
|
|
|
return (strtotime('next sat 00:00:00')) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last week start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PLastWeekStart()
|
|
|
|
|
{
|
|
|
|
|
return ($this->PThisWeekStart() - (86400 * 7));;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last week end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PLastWeekEnd()
|
|
|
|
|
{
|
|
|
|
|
return ($this->PThisWeekStart() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisMonthStart()
|
|
|
|
|
{
|
|
|
|
|
// get this month
|
|
|
|
|
$this_month = $this->PDate('Y/n/') . '1';
|
|
|
|
|
$result = $this->Parsi2Timestamp($this_month);
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisMonthStartEx($time)
|
|
|
|
|
{
|
|
|
|
|
// get this month
|
|
|
|
|
$this_month = $this->PDate('Y/n/', $time) . '1';
|
|
|
|
|
$result = $this->Parsi2Timestamp($this_month);
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisMonthEnd()
|
|
|
|
|
{
|
|
|
|
|
$last_day = $this->_pGetMonthDayCount($this->PDate('n'), $this->PDate('Y'));
|
|
|
|
|
|
|
|
|
|
$this_month = $this->PDate('Y/n/' . $last_day);
|
|
|
|
|
$result = $this->Parsi2Timestamp($this_month, '23:59:59');
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisMonthEndEx($time)
|
|
|
|
|
{
|
|
|
|
|
$last_day = $this->_pGetMonthDayCount($this->PDate('n', $time), $this->PDate('Y', $time));
|
|
|
|
|
|
|
|
|
|
$this_month = $this->PDate('Y/n/' . $last_day, $time);
|
|
|
|
|
$result = $this->Parsi2Timestamp($this_month, '23:59:59');
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last month start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PLastMonthStart()
|
|
|
|
|
{
|
|
|
|
|
$tmp = $this->PThisMonthStart();
|
|
|
|
|
$last_month_day_count = $this->_pGetMonthDayCount($this->PDate('n', $tmp - 1), $this->PDate('Y', $tmp - 1));
|
|
|
|
|
|
|
|
|
|
return $tmp - ($last_month_day_count * 86400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last month end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PLastMonthEnd()
|
|
|
|
|
{
|
|
|
|
|
return $this->PThisMonthStart() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this year start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisYearStart()
|
|
|
|
|
{
|
|
|
|
|
$past_day = $this->PDate('z', strtotime('yesterday'));
|
|
|
|
|
$result = strtotime('today') - (86400 * $past_day);
|
|
|
|
|
if ((int)$this->PDate('n') < 7) {
|
|
|
|
|
$result += 3600;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this year end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PThisYearEnd()
|
|
|
|
|
{
|
|
|
|
|
if ($this->IsLeapYear((int)$this->PDate('Y'))) {
|
|
|
|
|
return $this->PThisYearStart() + (86400 * 366) - 1;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->PThisYearStart() + (86400 * 365) - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian last year start
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PLastYearStart()
|
|
|
|
|
{
|
|
|
|
|
if ($this->IsLeapYear((int)$this->PDate('Y') - 1)) {
|
|
|
|
|
return $this->PThisYearStart() - (86400 * 365);
|
|
|
|
|
} else {
|
|
|
|
|
return $this->PThisYearStart() - (86400 * 364);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* persian this last year end
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function PLastYearEnd()
|
|
|
|
|
{
|
|
|
|
|
return $this->PThisYearStart() - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|