|
@@ 259-310 (lines=52) @@
|
| 256 |
|
* @since Oct, 17 2015 |
| 257 |
|
* @return object |
| 258 |
|
*/ |
| 259 |
|
public function hijriToJalali( $date_time ) { |
| 260 |
|
|
| 261 |
|
$this->date_time = $date_time; |
| 262 |
|
|
| 263 |
|
$this->year = $this->date_time->format( 'Y' ); |
| 264 |
|
|
| 265 |
|
$this->month = $this->date_time->format( 'm' ); |
| 266 |
|
|
| 267 |
|
$this->day = $this->date_time->format( 'd' ); |
| 268 |
|
|
| 269 |
|
$days_of_year = 0; |
| 270 |
|
|
| 271 |
|
$this->config = include( 'Hijri.php' ); |
| 272 |
|
|
| 273 |
|
foreach ( $this->config[ 'month_days_number' ] as $month => $value ) { |
| 274 |
|
|
| 275 |
|
if ( $this->month > $month ) $days_of_year += $value; |
| 276 |
|
|
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
$days_of_year += $this->day; |
| 280 |
|
|
| 281 |
|
$days_of_leap_years = intval( ( ( $this->year - 1 ) / 3 ) ); |
| 282 |
|
|
| 283 |
|
$days_of_hijri_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years ); |
| 284 |
|
|
| 285 |
|
$days_of_jalali_years = $days_of_hijri_years + 179; |
| 286 |
|
|
| 287 |
|
$days_of_jalali_years = $days_of_jalali_years - intval( ( ( $this->year - 43 ) / 4 ) ); |
| 288 |
|
|
| 289 |
|
$jalali_month = ( $days_of_jalali_years % 365 ); |
| 290 |
|
|
| 291 |
|
$jalali_year = intval( $days_of_jalali_years / 365 ) + 1; |
| 292 |
|
|
| 293 |
|
$this->config = include( 'Jalali.php' ); |
| 294 |
|
|
| 295 |
|
foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
| 296 |
|
|
| 297 |
|
if ( $jalali_month < $value ) break; |
| 298 |
|
|
| 299 |
|
$jalali_month -= $value; |
| 300 |
|
} |
| 301 |
|
|
| 302 |
|
$jalali_day = $jalali_month; |
| 303 |
|
|
| 304 |
|
$jalali_month = $month; |
| 305 |
|
|
| 306 |
|
$this->date_time->setDate( $jalali_year, $jalali_month, $jalali_day ); |
| 307 |
|
|
| 308 |
|
return $this->date_time; |
| 309 |
|
|
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
/** |
| 313 |
|
* convert hijri year to gregorian year |
|
@@ 317-368 (lines=52) @@
|
| 314 |
|
* @since Oct, 17 2015 |
| 315 |
|
* @return object |
| 316 |
|
*/ |
| 317 |
|
public function hijriToGregorian( $date_time ) { |
| 318 |
|
|
| 319 |
|
$this->date_time = $date_time; |
| 320 |
|
|
| 321 |
|
$this->year = $this->date_time->format( 'Y' ); |
| 322 |
|
|
| 323 |
|
$this->month = $this->date_time->format( 'm' ); |
| 324 |
|
|
| 325 |
|
$this->day = $this->date_time->format( 'd' ); |
| 326 |
|
|
| 327 |
|
$days_of_year = 0; |
| 328 |
|
|
| 329 |
|
$this->config = include( 'Hijri.php' ); |
| 330 |
|
|
| 331 |
|
foreach ( $this->config[ 'month_days_number' ] as $month => $value ) { |
| 332 |
|
|
| 333 |
|
if ( $this->month > $month ) $days_of_year += $value; |
| 334 |
|
|
| 335 |
|
} |
| 336 |
|
|
| 337 |
|
$days_of_year += $this->day; |
| 338 |
|
|
| 339 |
|
$days_of_leap_years = intval( ( ( $this->year - 1 ) / 3 ) ); |
| 340 |
|
|
| 341 |
|
$days_of_hijri_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years ); |
| 342 |
|
|
| 343 |
|
$days_of_gregorain_years = $days_of_hijri_years + 227078; |
| 344 |
|
|
| 345 |
|
$days_of_gregorain_years = $days_of_gregorain_years - intval( ( ( $this->year + 578 ) / 4 ) ); |
| 346 |
|
|
| 347 |
|
$gregorian_month = ( $days_of_gregorain_years % 365 ); |
| 348 |
|
|
| 349 |
|
$gregorian_year = intval( $days_of_gregorain_years / 365 ) + 1; |
| 350 |
|
|
| 351 |
|
$this->config = include( 'Gregorian.php' ); |
| 352 |
|
|
| 353 |
|
foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
| 354 |
|
|
| 355 |
|
if ( $gregorian_month < $value ) break; |
| 356 |
|
|
| 357 |
|
$gregorian_month -= $value; |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
$gregorian_day = $gregorian_month; |
| 361 |
|
|
| 362 |
|
$gregorian_month = $month; |
| 363 |
|
|
| 364 |
|
$this->date_time->setDate( $gregorian_year, $gregorian_month, $gregorian_day ); |
| 365 |
|
|
| 366 |
|
return $this->date_time; |
| 367 |
|
|
| 368 |
|
} |
| 369 |
|
|
| 370 |
|
} |
| 371 |
|
|