You are here

public static function LiveWeather::checkDayNight in Live Weather 8

Same name and namespace in other branches
  1. 8.2 src/LiveWeather.php \Drupal\live_weather\LiveWeather::checkDayNight()

Check Day or Night.

Overrides LiveWeatherInterface::checkDayNight

File

src/LiveWeather.php, line 87
Contains \Drupal\live_weather\LiveWeather.

Class

LiveWeather
Live weather.

Namespace

Drupal\live_weather

Code

public static function checkDayNight($date, $sunrise, $sunset) {
  $position = Unicode::strpos($date, ":");
  $tpb = Unicode::substr($date, $position - 2, 8);
  $actual_time = strtotime($tpb);
  $sunrise_time = strtotime($sunrise);
  $sunset_time = strtotime($sunset);
  if ($actual_time > $sunrise_time && $actual_time < $sunset_time) {
    return 'd';
  }
  else {
    return 'n';
  }
  return 'd';
}