You are here

function _datereminder_get_occurance_after_date in Date Reminder 7

Same name and namespace in other branches
  1. 6.2 includes/date.inc \_datereminder_get_occurance_after_date()
  2. 6 includes/date.inc \_datereminder_get_occurance_after_date()

Get date of next occurance after given date.

Parameters

field $df: The date field from node.

DateTime $dt: DateTime object for the date in question

Return value

DateTime DateTime object for next occurance after $dt.

2 calls to _datereminder_get_occurance_after_date()
datereminder_tokens in ./datereminder.module
Implements hook_tokens().
_datereminder_get_next_occurance in includes/date.inc
Return string datetime for next occurance after a suitable delay from now.

File

includes/date.inc, line 117
Some functions dealing with dates.

Code

function _datereminder_get_occurance_after_date($df, $dt) {
  $lang = key($df);
  if (isset($df[$lang])) {

    // Get map of type to format string.
    $dates = $df[$lang];
    if (!isset($dates[0])) {

      // Not sure why there would be *no* dates in the field, but...
      return NULL;
    }
    $ftmap = _datereminder_supported_date_field_types();
    $fmtstring = $ftmap[$dates[0]['date_type']];
    if (!$fmtstring) {

      // Shouldn't happen. Paranoia.
      return NULL;
    }

    // Deal with other TZ
    $dbTzStr = $dates[0]['timezone_db'];
    if ($dbTzStr != 'UTC') {
      $dbTz = new DateTimeZone($dbTzStr);
      $dt
        ->setTimeZone($dbTz);
    }

    // Format the date, as appropriate for this date field type.
    $datestr = $dt
      ->format($fmtstring);
    foreach ($dates as $dt) {
      $etime = $dt['value'];
      if (!isset($etime)) {
        continue;
      }
      if (strcmp($etime, $datestr) > 0) {

        // This is the one we want. Turn back into DateTime.
        return _datereminder_date_field_value_to_datetime($df, $etime, $lang);
      }
    }
  }
  return NULL;
}