Advertisement
Guest User

Untitled

a guest
Jun 24th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Luach\Controller;
  4.  
  5. use Zend\Mvc\Controller\ActionController,
  6.     Zend\View\Model\ViewModel;
  7.  
  8. class LuachController extends ActionController {
  9.  
  10.     public function indexAction() {
  11.         $aDates = $this->createDateRangeArray('2012-09-01', '2013-09-01');
  12.         foreach ($aDates as $aDate) {
  13.  
  14.             $aJulianFormat = $this->splitDate($aDate);
  15.             //         $aJulianFormat = array('month'=>date('m'), 'day'=>date('d'), 'year' => date('Y'));
  16.             $jewishDate = jdtojewish(
  17.                     gregoriantojd($aJulianFormat['month'],
  18.                             $aJulianFormat['day'],
  19.                             $aJulianFormat['year']),
  20.                             true,
  21.                             CAL_JEWISH_ADD_GERESHAYIM +
  22.                             CAL_JEWISH_ADD_ALAFIM +
  23.                             CAL_JEWISH_ADD_ALAFIM_GERESH
  24.             );
  25.             echo('jdtojewish' . ' : ' . $jewishDate . '<br>');
  26.             echo('iconv' . ' : ' . iconv('ISO-8859-8', 'UTF-8', $jewishDate) . '<br>');
  27.  
  28.         }
  29.  
  30.  
  31.     }
  32.  
  33.     private function createDateRangeArray($strDateFrom, $strDateTo) {
  34.         // takes two dates formatted as YYYY-MM-DD and creates an
  35.         // inclusive array of the dates between the from and to dates.
  36.         // could test validity of dates here but I'm already doing
  37.         // that in the main script
  38.  
  39.         $aryRange = array();
  40.  
  41.         $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
  42.         $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
  43.  
  44.         if ($iDateTo >= $iDateFrom) {
  45.             array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry
  46.  
  47.             while ($iDateFrom < $iDateTo) {
  48.                 $iDateFrom+=86400; // add 24 hours
  49.                 array_push($aryRange, date('Y-m-d', $iDateFrom));
  50.             }
  51.         }
  52.         return $aryRange;
  53.     }
  54.  
  55.     private function splitDate($sDate) {
  56.  
  57.         return date_parse_from_format("Y-m-d", $sDate);
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement