function weather_format_wind_speed in Weather 7.2
Same name and namespace in other branches
- 7.3 weather_theme.inc \weather_format_wind_speed()
Convert wind speed.
Parameters
int $wind_speed: Wind speed in m/s.
string $unit: Unit to be returned (km/h, knots, meter/s, ...).
Return value
string Formatted representation in the desired unit.
2 calls to weather_format_wind_speed()
- weather_format_wind in ./
weather_theme.inc - Convert wind.
- weather_handler_wind_speed::render in views_handlers/
weather_handler_wind_speed.inc - Render wind speed with selected unit.
File
- ./
weather_theme.inc, line 334 - Prepare themed weather output.
Code
function weather_format_wind_speed($wind_speed, $unit) {
if ($unit == 'mph') {
$result = t('!speed mph', array(
'!speed' => round($wind_speed * 2.23694, 1),
));
}
elseif ($unit == 'mph_value') {
$result = round($wind_speed * 2.23694, 1);
}
elseif ($unit == 'knots') {
$result = t('!speed knots', array(
'!speed' => round($wind_speed * 1.94384, 1),
));
}
elseif ($unit == 'knots_value') {
$result = round($wind_speed * 1.94384, 1);
}
elseif ($unit == 'kmh') {
$result = t('!speed km/h', array(
'!speed' => round($wind_speed * 3.6, 1),
));
}
elseif ($unit == 'kmh_value') {
$result = round($wind_speed * 3.6, 1);
}
elseif ($unit == 'beaufort') {
$beaufort = weather_calculate_beaufort($wind_speed);
$result = t('Beaufort !number', array(
'!number' => $beaufort['number'],
));
}
elseif ($unit == 'beaufort_value') {
$beaufort = weather_calculate_beaufort($wind_speed);
$result = $beaufort['number'];
}
elseif ($unit == 'mps_value') {
$result = $wind_speed;
}
else {
// Default to m/s.
$result = t('!speed meter/s', array(
'!speed' => $wind_speed,
));
}
return preg_replace("/([^ ]*) ([^ ]*)/", '<span style="white-space:nowrap;">\\1 \\2</span>', $result);
}