1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
| <?php
namespace app\help;
class Lunar { private $_SMDay = array(1 => 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); private $_LStart = 1950; private $_LMDay = array( array(47, 29, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29), array(36, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30), array(6, 29, 30, 29, 30, 59, 29, 30, 30, 29, 30, 29, 30, 29), array(44, 29, 30, 29, 29, 30, 30, 29, 30, 30, 29, 30, 29), array(33, 30, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30), array(23, 29, 30, 59, 29, 29, 30, 29, 30, 29, 30, 30, 30, 29), array(42, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30), array(30, 30, 29, 30, 29, 30, 29, 29, 59, 30, 29, 30, 29, 30), array(48, 30, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30), array(38, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29), array(27, 30, 29, 30, 29, 30, 59, 30, 29, 30, 29, 30, 29, 30), array(45, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30), array(35, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29), array(24, 30, 29, 30, 58, 30, 29, 30, 29, 30, 30, 30, 29, 29), array(43, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30), array(32, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29), array(20, 30, 30, 59, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30), array(39, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 30), array(29, 29, 30, 29, 30, 30, 29, 59, 30, 29, 30, 29, 30, 30), array(47, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29), array(36, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30), array(26, 29, 30, 29, 29, 59, 30, 29, 30, 30, 30, 29, 30, 30), array(45, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30), array(33, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30), array(22, 30, 30, 29, 59, 29, 30, 29, 29, 30, 30, 29, 30, 30), array(41, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30), array(30, 30, 30, 29, 30, 29, 30, 29, 59, 29, 30, 29, 30, 30), array(48, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 29), array(37, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29), array(27, 30, 29, 29, 30, 29, 60, 29, 30, 30, 29, 30, 29, 30), array(46, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30), array(35, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30), array(24, 30, 29, 30, 58, 30, 29, 29, 30, 29, 30, 30, 30, 29), array(43, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30), array(32, 30, 29, 30, 30, 29, 29, 30, 29, 29, 59, 30, 30, 30), array(50, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30), array(39, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 29), array(28, 30, 29, 30, 29, 30, 59, 30, 30, 29, 30, 29, 29, 30), array(47, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29), array(36, 30, 29, 29, 30, 29, 30, 29, 30, 29, 30, 30, 30), array(26, 29, 30, 29, 29, 59, 29, 30, 29, 30, 30, 30, 30, 30), array(45, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30), array(34, 29, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30), array(22, 29, 30, 59, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30), array(40, 30, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30), array(30, 29, 30, 30, 29, 30, 29, 30, 59, 29, 30, 29, 30, 30), array(49, 29, 30, 29, 30, 30, 29, 30, 29, 30, 30, 29, 29), array(37, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29), array(27, 30, 29, 29, 30, 58, 30, 30, 29, 30, 30, 29, 30, 29), array(46, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29), array(35, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29), array(23, 30, 30, 29, 59, 30, 29, 29, 30, 29, 30, 29, 30, 30), array(42, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29), array(31, 30, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30), array(21, 29, 59, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 30), array(39, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29), array(28, 30, 29, 30, 29, 30, 29, 59, 30, 30, 29, 30, 30, 30), array(48, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30), array(37, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30), array(25, 30, 30, 29, 29, 59, 29, 30, 29, 30, 29, 30, 30, 30), array(44, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30), array(33, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29), array(22, 30, 29, 30, 59, 30, 29, 30, 29, 30, 29, 30, 29, 30), array(40, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30), array(30, 29, 30, 29, 30, 29, 30, 29, 30, 59, 30, 29, 30, 30), array(49, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30, 29), array(38, 30, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30), array(27, 29, 30, 29, 30, 29, 59, 29, 30, 29, 30, 30, 30, 29), array(46, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30), array(35, 30, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30), array(24, 29, 30, 30, 59, 30, 29, 29, 30, 29, 30, 29, 30, 30), array(42, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29), array(31, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30), array(21, 29, 59, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 30), array(40, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29), array(28, 30, 29, 30, 29, 29, 59, 30, 29, 30, 30, 30, 29, 30), array(47, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 30, 29), array(36, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29), array(25, 30, 30, 30, 29, 59, 29, 30, 29, 29, 30, 30, 29, 30), array(43, 30, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30, 30), array(33, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29), array(22, 29, 30, 59, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30), array(41, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30), array(30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 59, 30, 30), array(49, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30), array(38, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30), array(27, 30, 30, 29, 30, 29, 59, 29, 29, 30, 29, 30, 30, 29), array(45, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30), array(34, 30, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30, 29), array(23, 30, 30, 29, 30, 59, 30, 29, 30, 29, 30, 29, 29, 30), array(42, 30, 29, 30, 30, 29, 30, 29, 30, 30, 29, 30, 29), array(31, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30), array(21, 29, 59, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 30), array(40, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30), array(29, 30, 29, 30, 29, 29, 30, 58, 30, 29, 30, 30, 30, 29), array(47, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30), array(36, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30), array(25, 30, 29, 30, 30, 59, 29, 30, 29, 29, 30, 29, 30, 29), array(44, 29, 30, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29), array(32, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29), array(22, 29, 30, 59, 29, 30, 29, 30, 30, 29, 30, 30, 29, 29), );
private function IsLeapYear($AYear) { return ($AYear % 4 == 0) && (($AYear % 100 != 0) || ($AYear % 400 == 0)); }
private function GetSMon($year, $month) { if ($this->IsLeapYear($year) && $month == 2) return 29; else return $this->_SMDay[$month]; }
private function LYearName($year) { $Name = array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九"); for ($i = 0; $i < 4; $i++) for ($k = 0; $k < 10; $k++) if ($year[$i] == $k) $tmp .= $Name[$k]; return $tmp; }
private function LMonName($month) { if ($month >= 1 && $month <= 12) { $Name = array(1 => "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"); return $Name[$month]; } return $month; }
private function LDayName($day) { if ($day >= 1 && $day <= 30) { $Name = array(1 => "初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十" ); return $Name[$day]; } return $day; }
public function S2L($date) { list($year, $month, $day) = explode("-", $date); if ($year <= 1951 || $month <= 0 || $day <= 0 || $year >= 2051) return false; $date1 = strtotime($year . "-01-01"); $date2 = strtotime($year . "-" . $month . "-" . $day); $days = round(($date2 - $date1) / 3600 / 24); $days += 1; $Larray = $this->_LMDay[$year - $this->_LStart]; if ($days <= $Larray[0]) { $Lyear = $year - 1; $days = $Larray[0] - $days; $Larray = $this->_LMDay[$Lyear - $this->_LStart]; if ($days < $Larray[12]) { $Lmonth = 12; $Lday = $Larray[12] - $days; } else { $Lmonth = 11; $days = $days - $Larray[12]; $Lday = $Larray[11] - $days; } } else { $Lyear = $year; $days = $days - $Larray[0]; for ($i = 1; $i <= 12; $i++) { if ($days > $Larray[$i]) $days = $days - $Larray[$i]; else { if ($days > 30) { $days = $days - $Larray[13]; $Ltype = 1; } $Lmonth = $i; $Lday = $days; break; } } } return mktime(0, 0, 0, $Lmonth, $Lday, $Lyear); }
public function L2S($date, $type = 0) { list($year, $month, $day) = explode("-", $date); $month = intval($month); if ($year <= 1951 || $month <= 0 || $day <= 0 || $year >= 2051) return false; $Larray = $this->_LMDay[$year - $this->_LStart]; if ($type == 1 && count($Larray) <= 12) return false; if ($Larray[$month] > 30 && $type == 1 && count($Larray) >= 13) $day = $Larray[13] + $day; $days = $day; for ($i = 0; $i <= $month - 1; $i++) $days += $Larray[$i]; if ($days > 366 || ($this->GetSMon($month, 2) != 29 && $days > 365)) { $Syear = $year + 1; if ($this->GetSMon($month, 2) != 29) $days -= 366; else $days -= 365; if ($days > $this->_SMDay[1]) { $Smonth = 2; $Sday = $days - $this->_SMDay[1]; } else { $Smonth = 1; $Sday = $days; } } else { $Syear = $year; for ($i = 1; $i <= 12; $i++) { if ($days > $this->GetSMon($Syear, $i)) $days -= $this->GetSMon($Syear, $i); else { $Smonth = $i; $Sday = $days; break; } } } return mktime(0, 0, 0, $Smonth, $Sday, $Syear); } }
|