Example #1
0
 /**
  *    Convert a date from Excel to PHP
  *
  *    @param        integer        $dateValue            Excel date/time value
  *    @param        boolean        $adjustToTimezone    Flag indicating whether $dateValue should be treated as
  *                                                    a UST timestamp, or adjusted to UST
  *    @param        string         $timezone            The timezone for finding the adjustment from UST
  *    @return       integer        PHP serialized date/time
  */
 public static function excelToPHP($dateValue = 0, $adjustToTimezone = false, $timezone = null)
 {
     if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
         $myexcelBaseDate = 25569;
         //    Adjust for the spurious 29-Feb-1900 (Day 60)
         if ($dateValue < 60) {
             --$myexcelBaseDate;
         }
     } else {
         $myexcelBaseDate = 24107;
     }
     // Perform conversion
     if ($dateValue >= 1) {
         $utcDays = $dateValue - $myexcelBaseDate;
         $returnValue = round($utcDays * 86400);
         if ($returnValue <= PHP_INT_MAX && $returnValue >= -PHP_INT_MAX) {
             $returnValue = (int) $returnValue;
         }
     } else {
         $hours = round($dateValue * 24);
         $mins = round($dateValue * 1440) - round($hours * 60);
         $secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
         $returnValue = (int) gmmktime($hours, $mins, $secs);
     }
     $timezoneAdjustment = $adjustToTimezone ? TimeZone::getTimezoneAdjustment($timezone, $returnValue) : 0;
     return $returnValue + $timezoneAdjustment;
 }