protected function ThemeService::formatWindchillTemperature in Weather 8
Same name and namespace in other branches
- 2.0.x src/Service/ThemeService.php \Drupal\weather\Service\ThemeService::formatWindchillTemperature()
Calculates windchill temperature.
Windchill temperature is only defined for temperatures at or below 10 °C (50 °F) and wind speeds above 1.34 m/s (3 mph). Bright sunshine may increase the wind chill temperature. @link http://en.wikipedia.org/wiki/Wind_chill.
Parameters
int $temperature: Temperature in degree celsius.
int $wind_speed: Wind speed in m/s.
string $unit: Unit to be returned (celsius, fahrenheit, ...).
Return value
string Formatted representation in the desired unit. If the windchill is not defined for the current conditions, returns NULL.
1 call to ThemeService::formatWindchillTemperature()
- ThemeService::setForecastsVariables in src/
Service/ ThemeService.php - Adds variables related to weather forecast.
File
- src/
Service/ ThemeService.php, line 347
Class
- ThemeService
- ThemeService service.
Namespace
Drupal\weather\ServiceCode
protected function formatWindchillTemperature($temperature, $wind_speed, $unit) {
// Set up the empty result, if windchill temperature is not defined
// for current conditions.
$result = NULL;
// First, check conditions for windchill temperature.
if ($temperature <= 10 and $wind_speed >= 1.34) {
// Convert wind speed to km/h for formula.
$wind_speed = $wind_speed * 3.6;
// Calculate windchill (in degree Celsius).
// The integer cast is necessary to avoid a result of '-0°C'.
$windchill = (int) round(13.12 + 0.6215000000000001 * $temperature - 11.37 * pow($wind_speed, 0.16) + 0.3965 * $temperature * pow($wind_speed, 0.16));
$result = $this
->formatTemperature($windchill, $unit);
}
return $result;
}