You are here

function cmfcCalendarV1Gregorian::dateTimeDiff in Calendar Systems 6.3

Same name and namespace in other branches
  1. 8 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()
  2. 8.2 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()
  3. 5 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()
  4. 6 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()
  5. 7.3 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()
  6. 7 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()
  7. 7.2 calendar/v1/calendarSystems/gregorian.class.inc.php \cmfcCalendarV1Gregorian::dateTimeDiff()

Date : 15-12-2003.

Ref: Dates go in "2003-12-31". Ref: Times go in "12:59:13". Ref: mktime(HOUR,MIN,SEC,MONTH,DAY,YEAR).

Splits the dates into parts, to be reformatted for mktime. $first_datetime = getdate($first_datetime); $second_datetime = getdate($second_datetime);

makes the dates and times into unix timestamps. $first_unix = mktime($first_datetime['hours'], $first_time_ex[1], $first_time_ex[2], $first_date_ex[1], $first_date_ex[2], $first_date_ex[0]); $second_unix = mktime($second_time_ex[0], $second_time_ex[1], $second_time_ex[2], $second_date_ex[1], $second_date_ex[2], $second_date_ex[0]); Gets the difference between the two unix timestamps.

Overrides cmfcCalendarV1::dateTimeDiff

File

calendar/v1/calendarSystems/gregorian.class.inc.php, line 165

Class

cmfcCalendarV1Gregorian
@desc

Code

function dateTimeDiff($first_timestamp, $second_timestamp) {

  // Author: Tone.
  // Date    : 15-12-2003.
  // Ref: Dates go in "2003-12-31".
  // Ref: Times go in "12:59:13".
  // Ref: mktime(HOUR,MIN,SEC,MONTH,DAY,YEAR).
  // Splits the dates into parts, to be reformatted for mktime.
  //    $first_datetime = getdate($first_datetime);
  //    $second_datetime = getdate($second_datetime);
  // makes the dates and times into unix timestamps.
  // $first_unix  = mktime($first_datetime['hours'], $first_time_ex[1], $first_time_ex[2], $first_date_ex[1], $first_date_ex[2], $first_date_ex[0]);
  // $second_unix  = mktime($second_time_ex[0], $second_time_ex[1], $second_time_ex[2], $second_date_ex[1], $second_date_ex[2], $second_date_ex[0]);
  // Gets the difference between the two unix timestamps.
  if (empty($first_timestamp) or $first_timestamp < 0 or empty($second_timestamp) or $second_timestamp < 0) {
    return false;
  }
  $timediff = $first_timestamp - $second_timestamp;

  // Works out the days, hours, mins and secs.
  $days = intval($timediff / 86400);
  $remain = $timediff % 86400;
  $hours = intval($remain / 3600);
  $remain = $remain % 3600;
  $mins = intval($remain / 60);
  $secs = $remain % 60;

  // Returns a pre-formatted string. Can be chagned to an array.
  $result['days'] = $days;
  $result['hours'] = $hours;
  $result['minutes'] = $mins;
  return $result;
}