You are here

public function ParserService::getWeather in Weather 2.0.x

Same name and namespace in other branches
  1. 8 src/Service/ParserService.php \Drupal\weather\Service\ParserService::getWeather()

Returns a weather object for the specified GeoID.

Parameters

string $geoid: GeoID of the place for which the weather is desired.

int $days: Return weather for specified number of days (0 = all available days).

bool $detailed: Return detailed forecasts or just one forecast per day.

Return value

array Weather array with forecast information.

File

src/Service/ParserService.php, line 425

Class

ParserService
Parsing of XML weather forecasts from yr.no.

Namespace

Drupal\weather\Service

Code

public function getWeather($geoid, $days = 0, $detailed = TRUE) {

  // We need this variable for tests in future.
  $time = time();

  // Make sure weather forecast for this GeoID exists in DB.
  $result = $this
    ->downloadWeather($geoid, $time);

  // Get weather from DB.
  $weather['forecasts'] = $this
    ->getForecastsFromDatabase($geoid, $result['utc_offset'], $days, $detailed, $time);
  $weather['utc_offset'] = $result['utc_offset'];
  return $weather;
}