You are here

function socialcalc_import_date_explicit in Sheetnode 7.2

Same name and namespace in other branches
  1. 5 socialcalc.inc \socialcalc_import_date_explicit()
  2. 6 socialcalc.inc \socialcalc_import_date_explicit()
  3. 7 socialcalc.inc \socialcalc_import_date_explicit()

Convert a date from PHP to SocialCalc date/time value.

Parameters

long $year:

long $month:

long $day:

long $hours:

long $minutes:

long $seconds:

Return value

long SocialCalc date/time value

1 call to socialcalc_import_date_explicit()
socialcalc_import_date in ./socialcalc.inc
Convert a date from PHP to SocialCalc date/time value.

File

./socialcalc.inc, line 1155
SocialCalc manipulation functions.

Code

function socialcalc_import_date_explicit($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0) {

  //
  //  Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
  //  This affects every date following 28th February 1900
  // .
  $excel1900isLeapYear = TRUE;
  if ($year == 1900 && $month <= 2) {
    $excel1900isLeapYear = FALSE;
  }
  $myExcelBaseDate = 2415020;

  // Julian base date Adjustment.
  if ($month > 2) {
    $month = $month - 3;
  }
  else {
    $month = $month + 9;
    --$year;
  }

  // Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0).
  $century = substr($year, 0, 2);
  $decade = substr($year, 2, 2);
  $excelDate = floor(146097 * $century / 4) + floor(1461 * $decade / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myExcelBaseDate + $excel1900isLeapYear;
  $excelTime = ($hours * 3600 + $minutes * 60 + $seconds) / 86400;
  return (double) $excelDate + $excelTime;
}