You are here

function socialcalc_export_date in Sheetnode 7

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

Convert a date from SocialCalc to a Unix timestamp.

Parameters

long $dateValue SocialCalc date/time value:

Return value

long Unix timestamp

1 call to socialcalc_export_date()
socialcalc_export_datetime in ./socialcalc.inc
Convert a date from Excel to a PHP DateTime object

File

./socialcalc.inc, line 802
SocialCalc manipulation functions Translated from socialcalc-3.js and companion files

Code

function socialcalc_export_date($dateValue = 0) {
  $myBaseDate = 25569;

  //  Adjust for the spurious 29-Feb-1900 (Day 60)
  if ($dateValue < 60) {
    --$myBaseDate;
  }

  // Perform conversion
  if ($dateValue >= 1) {
    $utcDays = $dateValue - $myBaseDate;
    $returnValue = round($utcDays * 24 * 60 * 60);
    if ($returnValue <= PHP_INT_MAX && $returnValue >= -PHP_INT_MAX) {
      $returnValue = (int) $returnValue;
    }
  }
  else {
    $hours = round($dateValue * 24);
    $mins = round($dateValue * 24 * 60) - round($hours * 60);
    $secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 60);
    $returnValue = (int) gmmktime($hours, $mins, $secs);
  }
  return $returnValue;
}