protected function ThemeService::formatWindSpeed in Weather 8
Same name and namespace in other branches
- 2.0.x src/Service/ThemeService.php \Drupal\weather\Service\ThemeService::formatWindSpeed()
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.
1 call to ThemeService::formatWindSpeed()
- ThemeService::formatWind in src/
Service/ ThemeService.php - Convert wind.
File
- src/
Service/ ThemeService.php, line 782
Class
- ThemeService
- ThemeService service.
Namespace
Drupal\weather\ServiceCode
protected function formatWindSpeed($wind_speed, $unit) {
if ($unit == 'mph') {
$result = $this
->t('@speed mph', [
'@speed' => round($wind_speed * 2.23694, 1),
]);
}
elseif ($unit == 'mph_value') {
$result = round($wind_speed * 2.23694, 1);
}
elseif ($unit == 'knots') {
$result = $this
->t('@speed knots', [
'@speed' => round($wind_speed * 1.94384, 1),
]);
}
elseif ($unit == 'knots_value') {
$result = round($wind_speed * 1.94384, 1);
}
elseif ($unit == 'kmh') {
$result = $this
->t('@speed km/h', [
'@speed' => round($wind_speed * 3.6, 1),
]);
}
elseif ($unit == 'kmh_value') {
$result = round($wind_speed * 3.6, 1);
}
elseif ($unit == 'beaufort') {
$beaufort = $this
->calculateBeaufort($wind_speed);
$result = $this
->t('Beaufort @number', [
'@number' => $beaufort['number'],
]);
}
elseif ($unit == 'beaufort_value') {
$beaufort = $this
->calculateBeaufort($wind_speed);
$result = $beaufort['number'];
}
elseif ($unit == 'mps_value') {
$result = $wind_speed;
}
else {
// Default to m/s.
$result = $this
->t('@speed meter/s', [
'@speed' => $wind_speed,
]);
}
return $result;
}