You are here

function weather_format_pressure in Weather 7.2

Same name and namespace in other branches
  1. 7.3 weather_theme.inc \weather_format_pressure()
  2. 7 weather_theme.inc \weather_format_pressure()

Convert pressure.

Parameters

int $pressure: Pressure in hPa.

string $unit: Unit to be returned (for example, inHg, mmHg, hPa, kPa).

Return value

string Formatted representation.

2 calls to weather_format_pressure()
theme_weather_forecast_preprocess in ./weather_theme.inc
Custom theme function for preprocessing the weather display.
weather_handler_pressure::render in views_handlers/weather_handler_pressure.inc
Render pressure with selected unit.

File

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

Code

function weather_format_pressure($pressure, $unit) {
  if ($unit == 'inhg') {
    $result = t('!pressure inHg', array(
      '!pressure' => round($pressure * 0.02953, 2),
    ));
  }
  elseif ($unit == 'inhg_value') {
    $result = round($pressure * 0.02953, 2);
  }
  elseif ($unit == 'mmhg') {
    $result = t('!pressure mmHg', array(
      '!pressure' => round($pressure * 0.7500599999999999, 0),
    ));
  }
  elseif ($unit == 'mmhg_value') {
    $result = round($pressure * 0.7500599999999999, 0);
  }
  elseif ($unit == 'kpa') {
    $result = t('!pressure kPa', array(
      '!pressure' => round($pressure / 10, 1),
    ));
  }
  elseif ($unit == 'kpa_value') {
    $result = round($pressure / 10, 1);
  }
  elseif ($unit == 'hpa_value') {
    $result = $pressure;
  }
  else {

    // Default to metric units.
    $result = t('!pressure hPa', array(
      '!pressure' => $pressure,
    ));
  }
  return preg_replace("/([^ ]*)&thinsp;([^ ]*)/", '<span style="white-space:nowrap;">\\1&thinsp;\\2</span>', $result);
}