function _weather_parse_timestamp in Weather 7
Same name and namespace in other branches
- 5.6 weather_parser.inc \_weather_parse_timestamp()
- 5 weather_parser.inc \_weather_parse_timestamp()
- 6.5 weather_parser.inc \_weather_parse_timestamp()
Extract timestamp.
Parameters
string $metar_raw: Raw METAR data to parse
Return value
string Datetime string (UTC) for database storage
1 call to _weather_parse_timestamp()
- weather_parse_metar in ./
weather_parser.inc - Parses a raw METAR data string.
File
- ./
weather_parser.inc, line 196 - Retrieves and parses raw METAR data and stores result in database.
Code
function _weather_parse_timestamp($metar_raw) {
// The format to match is DDHHMMZ, for example, 251720Z
if (preg_match('/ ([0-9]{2})([0-9]{2})([0-9]{2})Z /', $metar_raw, $matches)) {
// Construct the date
$month = gmdate("n");
$year = gmdate("Y");
// If the day is larger than the current day, it's most probably
// a day in the last month.
if ($matches[1] > gmdate("d")) {
$month -= 1;
}
return gmmktime($matches[2], $matches[3], 0, $month, $matches[1], $year);
}
}