|
@@ 247-294 (lines=48) @@
|
| 244 |
|
* @since Oct, 17 2015 |
| 245 |
|
* @return object |
| 246 |
|
*/ |
| 247 |
|
public function ghamariToShamsi( $date_time ) { |
| 248 |
|
|
| 249 |
|
$this->date_time = $date_time; |
| 250 |
|
|
| 251 |
|
$this->year = $this->date_time->format('Y'); |
| 252 |
|
|
| 253 |
|
$this->month = $this->date_time->format('m'); |
| 254 |
|
|
| 255 |
|
$this->day = $this->date_time->format('d'); |
| 256 |
|
|
| 257 |
|
$days_of_year = 0; |
| 258 |
|
|
| 259 |
|
foreach ( $this->config['islamic_month_days'] as $month => $value ) { |
| 260 |
|
|
| 261 |
|
if( $this->month > $month ) $days_of_year += $value; |
| 262 |
|
|
| 263 |
|
} |
| 264 |
|
|
| 265 |
|
$days_of_year += $this->day; |
| 266 |
|
|
| 267 |
|
$days_of_leap_years = intval( ( ( $this->year - 1 ) / 3 ) ); |
| 268 |
|
|
| 269 |
|
$days_of_ghamari_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years ); |
| 270 |
|
|
| 271 |
|
$days_of_shamsi_years = $days_of_ghamari_years + 179; |
| 272 |
|
|
| 273 |
|
$days_of_shamsi_years = $days_of_shamsi_years - intval( ( ( $this->year - 43 ) / 4 ) ); |
| 274 |
|
|
| 275 |
|
$shamsi_month = ( $days_of_shamsi_years % 365 ); |
| 276 |
|
|
| 277 |
|
$shamsi_year = intval( $days_of_shamsi_years / 365 ) + 1; |
| 278 |
|
|
| 279 |
|
foreach ($this->config['shamsi_month_days'] as $month => $value) { |
| 280 |
|
|
| 281 |
|
if ( $shamsi_month < $value ) break; |
| 282 |
|
|
| 283 |
|
$shamsi_month -= $value; |
| 284 |
|
} |
| 285 |
|
|
| 286 |
|
$shamsi_day = $shamsi_month; |
| 287 |
|
|
| 288 |
|
$shamsi_month = $month; |
| 289 |
|
|
| 290 |
|
$this->date_time->setDate( $shamsi_year, $shamsi_month, $shamsi_day ); |
| 291 |
|
|
| 292 |
|
return $this->date_time; |
| 293 |
|
|
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
/** |
| 297 |
|
* convert ghamari year to gregorian year |
|
@@ 301-348 (lines=48) @@
|
| 298 |
|
* @since Oct, 17 2015 |
| 299 |
|
* @return object |
| 300 |
|
*/ |
| 301 |
|
public function ghamariToGregorian( $date_time ) { |
| 302 |
|
|
| 303 |
|
$this->date_time = $date_time; |
| 304 |
|
|
| 305 |
|
$this->year = $this->date_time->format('Y'); |
| 306 |
|
|
| 307 |
|
$this->month = $this->date_time->format('m'); |
| 308 |
|
|
| 309 |
|
$this->day = $this->date_time->format('d'); |
| 310 |
|
|
| 311 |
|
$days_of_year = 0; |
| 312 |
|
|
| 313 |
|
foreach ( $this->config['islamic_month_days'] as $month => $value ) { |
| 314 |
|
|
| 315 |
|
if( $this->month > $month ) $days_of_year += $value; |
| 316 |
|
|
| 317 |
|
} |
| 318 |
|
|
| 319 |
|
$days_of_year += $this->day; |
| 320 |
|
|
| 321 |
|
$days_of_leap_years = intval( ( ( $this->year - 1 ) / 3 ) ); |
| 322 |
|
|
| 323 |
|
$days_of_ghamari_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years ); |
| 324 |
|
|
| 325 |
|
$days_of_gregorain_years = $days_of_ghamari_years + 227078; |
| 326 |
|
|
| 327 |
|
$days_of_gregorain_years = $days_of_gregorain_years - intval( ( ( $this->year + 578 ) / 4 ) ); |
| 328 |
|
|
| 329 |
|
$gregorian_month = ( $days_of_gregorain_years % 365 ); |
| 330 |
|
|
| 331 |
|
$gregorian_year = intval( $days_of_gregorain_years / 365 ) + 1; |
| 332 |
|
|
| 333 |
|
foreach ($this->config['gregorian_month_days'] as $month => $value) { |
| 334 |
|
|
| 335 |
|
if ( $gregorian_month < $value ) break; |
| 336 |
|
|
| 337 |
|
$gregorian_month -= $value; |
| 338 |
|
} |
| 339 |
|
|
| 340 |
|
$gregorian_day = $gregorian_month; |
| 341 |
|
|
| 342 |
|
$gregorian_month = $month; |
| 343 |
|
|
| 344 |
|
$this->date_time->setDate( $gregorian_year, $gregorian_month, $gregorian_day ); |
| 345 |
|
|
| 346 |
|
return $this->date_time; |
| 347 |
|
|
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
} |
| 351 |
|
?> |