You are here

function _weather_parse_timestamp in Weather 6.5

Same name and namespace in other branches
  1. 5.6 weather_parser.inc \_weather_parse_timestamp()
  2. 5 weather_parser.inc \_weather_parse_timestamp()
  3. 7 weather_parser.inc \_weather_parse_timestamp()

Extract the timestamp

Parameters

string Raw METAR data to parse:

array Parsed METAR data, will be altered:

1 call to _weather_parse_timestamp()
weather_parse_metar in ./weather_parser.inc
Parses a raw METAR data string

File

./weather_parser.inc, line 105

Code

function _weather_parse_timestamp($metar_raw, &$metar) {
  if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})Z$/', $metar_raw, $matches)) {
    $timestamp['year'] = gmdate('Y');
    $timestamp['month'] = gmdate('n');
    $timestamp['day'] = $matches[1];
    $timestamp['hour'] = $matches[2];
    $timestamp['minute'] = $matches[3];

    // if the current day is lower than the one from the METAR data,
    // it must be a day from last month
    // Note: in case even the year wraps (month = 0 -> month = 12, year--),
    // the gmmktime() function further down will take care of this.
    if (gmdate('d') < $timestamp['day']) {
      $timestamp['month']--;
    }
    $metar['reported_on'] = gmmktime($timestamp['hour'], $timestamp['minute'], 0, $timestamp['month'], $timestamp['day'], $timestamp['year']);
  }
}