Example #1
0
 public static function jdtounix($jd)
 {
     $tz = new DateTimeZone(date_default_timezone_get() ?: 'UTC');
     $time = jdtounix($jd);
     $offset = $tz->getOffset(new DateTime("now", $tz));
     return $time + $offset;
 }
Example #2
0
 public function info($datetime = null)
 {
     if (DevValue::isNull($datetime)) {
         return $this->_data;
     }
     $timestamp = $this->timestamp($datetime);
     $today = array();
     $count = 0;
     $today = getdate($timestamp);
     $timestamp2 = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
     $first = getdate($timestamp2);
     $sd = $today['mday'];
     $tsd = 28;
     $numdays = cal_days_in_month(CAL_GREGORIAN, $today['mon'], $today['year']);
     $sm = isset($sm) && is_numeric($sm) ? $sm : '';
     $sy = isset($sy) && is_numeric($sy) ? $sy : '';
     if ($sm <= 12 && $sm >= 0 && $sy != '') {
         $jday = juliantojd($sm, $sd, $sy);
         $timestamp = jdtounix($jday);
         $today = getdate($timestamp);
         $numdays = cal_days_in_month(CAL_GREGORIAN, $today['mon'], $today['year']);
         $timestamp2 = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
         $first = getdate($timestamp2);
     }
     $last_month = $today['mon'] - 1;
     if ($last_month < 1) {
         $last_month = 11;
         $last_year = $today['year'] - 1;
     } else {
         $last_year = $today['year'];
     }
     $next_month = $today['mon'] + 1;
     if ($next_month >= 12) {
         $next_month = 1;
         $next_year = $today['year'] + 1;
     } else {
         $next_year = $today['year'];
     }
     $date = array();
     $date['day'] = (int) $sd;
     $date['firstweekday'] = $first['wday'];
     $date['year'] = (int) $today['year'];
     $date['lastyear'] = (int) $last_year;
     $date['nextyear'] = (int) $next_year;
     $date['month'] = (int) $today['mon'];
     $date['lastmonth'] = (int) $last_month;
     $date['nextmonth'] = (int) $next_month;
     $date['daysinmonth'] = (int) $numdays;
     $date['second'] = (int) $today['seconds'];
     $date['minute'] = (int) $today['minutes'];
     $date['hour'] = (int) $today['hours'];
     $date['timestamp'] = $today[0];
     $date['timezone'] = '';
     $date['offset'] = '';
     // $this->assign($date);
     //Phew! that was a lot of work!
     return $date;
 }
function dev_get_date_info($sm = '', $sy = '', $timestamp = '')
{
    $today;
    $count;
    $undefined;
    if ($timestamp == '') {
        $timestamp = mktime();
    }
    $today = getdate($timestamp);
    $timestamp2 = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
    $first = getdate($timestamp2);
    $sd = $today['mday'];
    $tsd = 28;
    $numdays = cal_days_in_month(CAL_GREGORIAN, $today['mon'], $today['year']);
    $sm = isset($sm) && is_numeric($sm) ? $sm : '';
    $sy = isset($sy) && is_numeric($sy) ? $sy : '';
    if ($sm <= 12 && $sm >= 0 && $sy != '') {
        $jday = juliantojd($sm, $sd, $sy);
        $timestamp = jdtounix($jday);
        $today = getdate($timestamp);
        $numdays = cal_days_in_month(CAL_GREGORIAN, $today['mon'], $today['year']);
        $timestamp2 = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
        $first = getdate($timestamp2);
    }
    $last_month = $today['mon'] - 1;
    if ($last_month < 1) {
        $last_month = 11;
        $last_year = $today['year'] - 1;
    } else {
        $last_year = $today['year'];
    }
    $next_month = $today['mon'] + 1;
    if ($next_month >= 12) {
        $next_month = 1;
        $next_year = $today['year'] + 1;
    } else {
        $next_year = $today['year'];
    }
    $date = array();
    $date['day'] = $sd;
    $date['firstweekday'] = $first['wday'];
    $date['year'] = $today['year'];
    $date['lastyear'] = $last_year;
    $date['nextyear'] = $next_year;
    $date['month'] = $today['mon'];
    $date['lastmonth'] = $last_month;
    $date['nextmonth'] = $next_month;
    $date['daysinmonth'] = $numdays;
    return $date;
}
 public function loadHolidays()
 {
     $jdDate = cal_to_jd(CAL_GREGORIAN, date('m'), date('d'), date('Y'));
     $hebrewDate = jdtojewish($jdDate);
     list($hebrewMonth, $hebrewDay, $hebrewYear) = explode('/', $hebrewDate);
     $holidays = array();
     $currYear = $hebrewYear - 1;
     // subtract a year for some reason
     $nextYear = $currYear + 1;
     foreach ($this->holidays as $key => $val) {
         $julianDate = jewishtojd($val[0], $val[1], $currYear);
         if (jdtounix($julianDate) < time()) {
             $julianDate = jewishtojd($val[0], $val[1], $nextYear);
             if (jdtounix($julianDate) < time()) {
                 $julianDate = jewishtojd($val[0], $val[1], $nextYear + 1);
             }
         }
         $unixTime = jdtounix($julianDate);
         $unixTime += 86400;
         // add 1 day for some reason
         $holidays[$key] = '@' . $unixTime;
     }
     return $holidays;
 }
Example #5
0
<?php

echo date("Y-m-d", jdtounix(2440588)) . "\n";
echo date("Y-m-d", jdtounix(2452162)) . "\n";
echo date("Y-m-d", jdtounix(2453926)) . "\n";
Example #6
0
 /**
  * Return the timestamp of the entry.
  *
  * The timestamp held by this entry is returned in one of three
  * formats: as a standard UNIX timestamp (default), as a fractional
  * Julian Day Count, or as a string.
  *
  * @param int the type of the timestamp. This must be one of
  * {@link UNIX_TIMESTAMP}, {@link EXIF_STRING}, or
  * {@link JULIAN_DAY_COUNT}.
  *
  * @return int the timestamp held by this entry in the correct form
  * as indicated by the type argument. For {@link UNIX_TIMESTAMP}
  * this is an integer counting the number of seconds since January
  * 1st 1970, for {@link EXIF_STRING} this is a string of the form
  * 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a
  * floating point number where the integer part denotes the day
  * count and the fractional part denotes the time of day (0.25 means
  * 6:00, 0.75 means 18:00).
  */
 function getValue($type = self::UNIX_TIMESTAMP)
 {
     switch ($type) {
         case self::UNIX_TIMESTAMP:
             $seconds = jdtounix($this->day_count);
             if ($seconds === false) {
                 /* jdtounix() return false if the Julian Day Count is outside
                  * the range of a UNIX timestamp. */
                 return false;
             } else {
                 return $seconds + $this->seconds;
             }
         case self::EXIF_STRING:
             list($month, $day, $year) = explode('/', jdtogregorian($this->day_count));
             $hours = (int) ($this->seconds / 3600);
             $minutes = (int) ($this->seconds % 3600 / 60);
             $seconds = $this->seconds % 60;
             return sprintf('%04d:%02d:%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds);
         case self::JULIAN_DAY_COUNT:
             return $this->day_count + $this->seconds / 86400;
         default:
             throw new PelInvalidArgumentException('Expected UNIX_TIMESTAMP (%d), ' . 'EXIF_STRING (%d), or ' . 'JULIAN_DAY_COUNT (%d) for $type, ' . 'got %d.', self::UNIX_TIMESTAMP, self::EXIF_STRING, self::JULIAN_DAY_COUNT, $type);
     }
 }
Example #7
0
 function printMonth($date)
 {
     $this->date = $date;
     $this->JDtoYMD($date, $year, $month, $day);
     $this->AddPage();
     // compute size base on current settings
     $width = $this->w - $this->lMargin - $this->rMargin;
     $height = $this->h - $this->tMargin - $this->bMargin;
     // print prev and next calendars
     $this->setXY($this->lMargin, $this->tMargin);
     $this->tinyCalendar($this->lastMonth($date), $this->tinySquareSize);
     $this->setXY($this->lMargin + $width - $this->tinySquareSize * 7, $this->tMargin);
     $this->tinyCalendar($this->nextMonth($date), $this->tinySquareSize);
     // print header
     $firstLine = $this->tinySquareSize * 8 + $this->tMargin;
     $monthStr = strtoupper(gmdate("F Y", jdtounix($date)));
     $this->SetXY($this->lMargin, $this->tMargin);
     $this->SetFont("Times", "B", $this->headerFontSize);
     $this->Cell($width, $firstLine, $monthStr, 0, 0, "C");
     // compute number of weeks in month.
     $wd = gmdate("w", jdtounix($date));
     $start = $date - $wd;
     $numDays = $this->nextMonth($date) - $start;
     $numWeeks = 0;
     while ($numDays > 0) {
         $numDays -= 7;
         ++$numWeeks;
     }
     // compute horizontal lines
     $this->squareHeight = ($height - 6 - $firstLine) / $numWeeks;
     $horizontalLines = array($firstLine, 6);
     for ($i = 0; $i < $numWeeks; ++$i) {
         $horizontalLines[$i + 2] = $this->squareHeight;
     }
     // compute vertical lines
     $this->squareWidth = $width / 7;
     $verticalLines = array($this->lMargin, $this->squareWidth, $this->squareWidth, $this->squareWidth, $this->squareWidth, $this->squareWidth, $this->squareWidth, $this->squareWidth);
     // print days of week
     $x = 0;
     $this->SetFont("Times", "B", 12);
     for ($i = 1; $i <= 7; ++$i) {
         $x += $verticalLines[$i - 1];
         $this->SetXY($x, $firstLine);
         $day = gmdate("l", jdtounix($this->MDYtoJD(2, $i, 2009)));
         $this->Cell($verticalLines[$i], 6, $day, 0, 0, "C");
     }
     // print numbers in boxes
     $wd = gmdate("w", jdtounix($date));
     $cur = $date - $wd;
     $this->SetFont("Times", "B", 20);
     $x = 0;
     $y = $horizontalLines[0];
     for ($k = 0; $k < $numWeeks; $k++) {
         $y += $horizontalLines[$k + 1];
         for ($i = 0; $i < 7; $i++) {
             $this->JDtoYMD($cur, $curYear, $curMonth, $curDay);
             $x += $verticalLines[$i];
             $this->squareWidth = $verticalLines[$i + 1];
             if ($curMonth == $month) {
                 $this->setXY($x, $y);
                 $this->printHoliday($cur);
                 $this->setXY($x, $y);
                 $this->printDay($cur);
                 $this->SetFont("Times", "B", 20);
                 $this->SetXY($x, $y + 1);
                 $this->Cell(5, 5, $curDay);
             }
             ++$cur;
         }
         $x = 0;
     }
     // print horizontal lines
     $ly = 0;
     $ry = 0;
     foreach ($horizontalLines as $key => $value) {
         $ly += $value;
         $ry += $value;
         $this->Line($this->lMargin, $ly, $this->lMargin + $width, $ry);
     }
     // print vertical lines
     $lx = 0;
     $rx = 0;
     foreach ($verticalLines as $key => $value) {
         $lx += $value;
         $rx += $value;
         $this->Line($lx, $firstLine, $rx, $firstLine + 6 + $this->squareHeight * $numWeeks);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function fromJulianDay($julian_day)
 {
     return new NativeDate(jdtounix($julian_day));
 }
Example #9
0
 /**
  * Get Unix timestamp for midnight on Easter of a given year.
  *
  * Shim implementation of \easter_date()
  *
  * @link https://php.net/easter_date
  *
  * @param int $year
  *
  * @return int
  */
 public static function easterDate($year)
 {
     if ($year < 1970 || $year > 2037) {
         return trigger_error('This function is only valid for years between 1970 and 2037 inclusive', E_USER_WARNING);
     }
     $gregorian = new GregorianCalendar();
     $days = $gregorian->easterDays($year);
     // Calculate time-zone offset
     $date_time = new \DateTime('now', new \DateTimeZone(date_default_timezone_get()));
     $offset_seconds = $date_time->format('Z');
     if ($days < 11) {
         return jdtounix($gregorian->ymdToJd($year, 3, $days + 21)) - $offset_seconds;
     } else {
         return jdtounix($gregorian->ymdToJd($year, 4, $days - 10)) - $offset_seconds;
     }
 }
Example #10
0
 /**
  * @desc get unix timestamp for the date and time (this is NOT in GMT)
  * @return int
  */
 public function get_ts($gmt = true)
 {
     $ts = jdtounix($this->jd) + $this->h * 3600 + $this->m * 60 + $this->s;
     if ($gmt) {
         $ts -= $this->get_timezone_offset();
     }
     return $ts;
 }
 public function GetNextRecord($FieldCaptions = false, $ShowDeleted = false)
 {
     $Return = NULL;
     $Record = array();
     $this->CurrentRowNumber++;
     if (!$this->FileOpened) {
         $Return = false;
     } elseif ($this->CurrentRowNumber > $this->DB_Records || feof($this->FileHandle)) {
         $Return = NULL;
     } else {
         // File open and not EOF
         if (!$ShowDeleted) {
             while (fread($this->FileHandle, 1) == '*') {
                 // Deleted flag
                 fseek($this->FileHandle, $this->DB_RecordLength - 1, SEEK_CUR);
                 $this->CurrentRowNumber++;
             }
             if ($this->CurrentRowNumber > $this->DB_Records || feof($this->FileHandle)) {
                 return NULL;
             }
         } else {
             fseek($this->FileHandle, 1, SEEK_CUR);
         }
         foreach ($this->DB_Fields as $Field) {
             $RawData = fread($this->FileHandle, $Field["Size"]);
             // Checking for memo reference
             if (($Field["Type"] == "M" or $Field["Type"] == "G" or $Field["Type"] == "P") and $Field["Size"] == 4) {
                 if (!empty($RawData)) {
                     // Memo, General, Picture
                     $Memo_BO = unpack("V", $RawData);
                     if ($this->Memo_Opened and $Memo_BO[1] != 0) {
                         fseek($this->Memo_Handle, $Memo_BO[1] * $this->Memo_BlockSize);
                         $Type = unpack("N", fread($this->Memo_Handle, 4));
                         //if(true || $Type[1] == "1") {
                         $Len = unpack("N", fread($this->Memo_Handle, 4));
                         $Value = rtrim(fread($this->Memo_Handle, $Len[1]), ' ');
                         //} else {
                         //    // Pictures will not be shown
                         //    $Value = "{BINARY_PICTURE}";
                         //}
                     } else {
                         $Value = '';
                     }
                 } else {
                     $Value = '';
                 }
             } else {
                 if ($Field["Type"] == 'V') {
                     // Varchar
                     $Len = ord(substr($RawData, -1));
                     $Value = substr($RawData, 0, $Len);
                 } else {
                     if ($Field["Type"] == 'C') {
                         // Char
                         $Value = rtrim($RawData, ' ');
                     } else {
                         if ($Field["Type"] == 'L') {
                             // Logical (Boolean)
                             $Value = !empty($RawData) && ($RawData[0] == 'Y' || $RawData[0] == 'T') ? 1 : 0;
                         } else {
                             if ($Field["Type"] == 'Y') {
                                 // Currency
                                 if (false && version_compare(PHP_VERSION, '5.6.3') >= 0) {
                                     $Value = unpack('P', $RawData);
                                     $Value = $Value[1] / 10000;
                                 } else {
                                     list($lo, $hi) = array_values(unpack('V2', $RawData));
                                     // 64-bit compatible PHP shortcut
                                     if (false && PHP_INT_SIZE >= 8) {
                                         if ($hi < 0) {
                                             $hi += 1 << 32;
                                         }
                                         if ($lo < 0) {
                                             $lo += 1 << 32;
                                         }
                                         $Value = (($hi << 32) + $lo) / 10000;
                                     } else {
                                         // No 64-bit magics
                                         if ($hi == 0) {
                                             // No high-byte, no negative flag
                                             if ($lo > 0) {
                                                 $Value = $lo / 10000;
                                             } else {
                                                 $Value = bcdiv(sprintf("%u", $lo), 10000, 4);
                                             }
                                         } elseif ($hi == -1) {
                                             // No high-byte, with negative flag
                                             if ($lo < 0) {
                                                 $Value = $lo / 10000;
                                             } else {
                                                 // sprintf is 10% faster than bcadd
                                                 $Value = bcdiv(sprintf("%.0f", $lo - 4294967296.0), 10000, 4);
                                             }
                                         } else {
                                             $negativeSign = '';
                                             $negativeOffset = 0;
                                             if ($hi < 0) {
                                                 $hi = ~$hi;
                                                 $lo = ~$lo;
                                                 $negativeOffset = 1;
                                                 $negativeSign = '-';
                                             }
                                             $hi = sprintf("%u", $hi);
                                             $lo = sprintf("%u", $lo);
                                             // 4294967296 = 2^32 = bcpow(2, 32)
                                             $Value = bcdiv($negativeSign . bcadd(bcadd($lo, bcmul($hi, "4294967296")), $negativeOffset), 10000, 4);
                                         }
                                     }
                                 }
                             } else {
                                 if ($Field["Type"] == 'D') {
                                     // Date
                                     if ($RawData != '        ') {
                                         $Value = substr($RawData, 0, 4) . '-' . substr($RawData, 4, 2) . '-' . substr($RawData, 6);
                                     } else {
                                         $Value = '1899-12-30';
                                     }
                                 } else {
                                     if ($Field["Type"] == 'I') {
                                         // Integer
                                         if (!empty($RawData)) {
                                             $Value = unpack('V', $RawData);
                                             $Value = $Value[1];
                                         } else {
                                             $Value = 0;
                                         }
                                     } else {
                                         if ($Field["Type"] == 'B') {
                                             // Double
                                             $Value = unpack('d', $RawData);
                                             $Value = $Value[1];
                                         } else {
                                             if ($Field["Type"] == 'Q') {
                                                 // VarBinary
                                                 $Len = ord(substr($RawData, -1));
                                                 $Value = substr($RawData, 0, $Len);
                                             } else {
                                                 if ($Field["Type"] == 'T') {
                                                     // DateTime (Timestamp)
                                                     if (!empty($RawData)) {
                                                         $Value = unpack('V2', $RawData);
                                                         $Date = jdtounix($Value[1]);
                                                         $Time = round($Value[2] / 1000);
                                                         if ($Date === false) {
                                                             $Value = '1899-12-30 ' . gmdate('H:i:s', $Time);
                                                         } else {
                                                             $Value = gmdate('Y-m-d H:i:s', $Date + $Time);
                                                         }
                                                     } else {
                                                         $Value = '1899-12-30 00:00:00';
                                                     }
                                                 } else {
                                                     if ($Field["Type"] == 'N' || $Field["Type"] == 'F' || $Field["Type"] == '+') {
                                                         // Numeric, Float, Autoincrement
                                                         $Value = (double) trim($RawData);
                                                     } else {
                                                         if ($Field["Type"] == '0') {
                                                             // System 'is nullable' column
                                                             continue;
                                                         } else {
                                                             // Unknown type?
                                                             //var_dump($Field); var_dump($RawData); die();
                                                             $Value = trim($RawData);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($FieldCaptions) {
                 $Record[$Field["Name"]] = $Value;
             } else {
                 $Record[] = $Value;
             }
         }
         $Return = $Record;
     }
     return $Return;
 }
 /**
  * Add a number of workdays to a start date
  *
  * The number of workdays is not allowed to be larger than 1 year (i.e. 365/366 days)
  * The year must be within the unix epoche (Gregorian years between 1970 and 2037 or 2440588 <= jday <= 2465342)
  * @param integer $startday Day of start date
  * @param integer $startmonth Month of start date
  * @param integer $startyear Year of start date
  * @param integer $workdays Number of workdays to add to startdate (must be >= 0)
  * @param integer $country Country for which to calculate the working days
  * @param integer $federal_state Federal state of given country for which to calculate the working days
  * @param integer $religion Religion for which to calculate the working days
  * @param integer &$newday Day of end date
  * @param integer &$newmonth Month of end date
  * @param integer &$newyear Year of end date
  * @static
  */
 function add_number_of_workdays($startday, $startmonth, $startyear, $workdays, $country, $federal_state, $religion)
 {
     $jd = gregoriantojd($startmonth, $startday, $startyear) + 1;
     $timestamp = jdtounix($jd);
     $startday = date("d", $timestamp);
     $startmonth = date("m", $timestamp);
     $startyear = date("Y", $timestamp);
     $addwdays = $workdays;
     for (;;) {
         $jd += $addwdays;
         $timestamp = jdtounix($jd);
         $newday = date("d", $timestamp);
         $newmonth = date("m", $timestamp);
         $newyear = date("Y", $timestamp);
         $wdays = $this->get_number_of_workdays($startday, $startmonth, $startyear, $newday, $newmonth, $newyear, $country, $federal_state, $religion);
         // echo $newyear . '-' . $newmonth . '-' . $newday . ':' . $wdays . "\n";
         if ($wdays == $workdays) {
             break;
         }
         $addwdays = $workdays - $wdays;
     }
     $days = array('newday' => $newday, 'newmonth' => $newmonth, 'newyear' => $newyear);
     return $days;
 }
Example #13
0
function hanukkahStart($year = null)
{
    $reference = ($year == '2021' || $year == '2032' ? '11/1/' : '12/1/') . ($year !== null ? $year : date('Y'));
    list($month, $day, $year) = explode("/", jdtojewish(unixtojd(strtotime($reference))));
    return jdtounix(jewishtojd(3, 25, $year));
}