You are here

function weather_format_suninfo in Weather 7

Format sunrise and sunset times.

Parameters

int $sunrise: Time of sunrise (UTC) as UNIX timestamp.

int $sunset: Time of sunset (UTC) as UNIX timestamp.

Return value

string Formatted representation.

1 call to weather_format_suninfo()
theme_weather_theming in ./weather_theme.inc
Custom theme function for preprocessing the weather display.

File

./weather_theme.inc, line 569
Prepare themed weather output.

Code

function weather_format_suninfo($sunrise, $sunset) {
  if (is_null($sunrise)) {
    $result['sunrise'] = t('No sunrise today');
    $result['sunset'] = NULL;
  }
  elseif (is_null($sunset)) {
    $result['sunrise'] = NULL;
    $result['sunset'] = t('No sunset today');
  }
  else {

    // Try to extract a time format from the system wide date format.
    $date_format_short = variable_get('date_format_short', 'm/d/Y - H:i');
    preg_match("/[GgHh].*?i(.*?[Aa])?/", $date_format_short, $matches);
    if (isset($matches[0])) {
      $format = $matches[0];
    }
    else {
      $format = 'G:i';
    }
    $time = format_date($sunrise, 'custom', $format);
    $result['sunrise'] = t('Sunrise: !sunrise', array(
      '!sunrise' => $time,
    ));
    $time = format_date($sunset, 'custom', $format);
    $result['sunset'] = t('Sunset: !sunset', array(
      '!sunset' => $time,
    ));
  }
  return $result;
}