CVS: phpweather/db pw_db_mysql.php,1.11,1.12 pw_db_null.php,1.5,1.6
Brought to you by:
iridium
From: Etienne T. <eti...@us...> - 2004-01-30 20:48:12
|
Update of /cvsroot/phpweather/phpweather/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30964/db Modified Files: pw_db_mysql.php pw_db_null.php Log Message: Fixed the timestamp for METAR retreival and archiving in mysql and null backends. The timestamp is kept as a unix timestamp (UTC) in the objects. The mysql backend has been modified to keep a UTC format in the table. Index: pw_db_mysql.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/db/pw_db_mysql.php,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- pw_db_mysql.php 3 Jan 2004 18:38:43 -0000 1.11 +++ pw_db_mysql.php 30 Jan 2004 20:46:36 -0000 1.12 @@ -185,9 +185,9 @@ */ function insert_metar($icao, $metar, $timestamp, $time) { $this->query(sprintf('INSERT INTO %s SET icao = "%s", time = "%s", ' . - 'metar = "%s", timestamp = FROM_UNIXTIME(%d)', - $this->properties['db_metars'], $icao, $time, - addslashes($metar), intval($timestamp))); + 'metar = "%s", timestamp = "%s"', + $this->properties['db_metars'], $icao, tms_unix2date($time), + addslashes($metar), tms_unix2date($timestamp))); $this->insert_metar_arch($icao, $metar, $time); } @@ -202,10 +202,10 @@ */ function update_metar($icao, $metar, $timestamp, $time) { $this->query(sprintf('UPDATE %s' . - ' SET metar = "%s", timestamp = FROM_UNIXTIME(%d)' . + ' SET metar = "%s", time = "%s", timestamp = "%s"' . ' WHERE icao = "%s"', $this->properties['db_metars'], addslashes($metar), - intval($timestamp), $icao)); + tms_unix2date($time), tms_unix2date($timestamp), $icao)); $this->insert_metar_arch($icao, $metar, $time); } @@ -226,12 +226,12 @@ $this->query(sprintf('DELETE FROM %s WHERE icao = "%s" AND ' . 'time = "%s"' , $this->properties['db_metars_arch'], - $icao,$time)); + $icao, tms_unix2date($time))); $this->query(sprintf('INSERT IGNORE INTO %s SET icao = "%s", ' . 'time = "%s", ' . 'metar = "%s"', $this->properties['db_metars_arch'], $icao, - $time, + tms_unix2date($time), addslashes($metar))); } } @@ -252,21 +252,23 @@ if($time_from===false || $this->properties['archive_metars']===false) { /* fetch the current metar */ - $query = sprintf('SELECT metar, UNIX_TIMESTAMP(timestamp) AS timestamp, time' . + $query = sprintf('SELECT metar, timestamp,' . + ' time' . ' FROM %s WHERE icao = "%s" LIMIT 1', $this->properties['db_metars'], $icao); } else if ($time_to!==false) { /* fetch archived metars between $time_from and $time_to */ - $query = sprintf('SELECT metar, UNIX_TIMESTAMP(time) AS timestamp, time' . + $query = sprintf('SELECT metar, time AS timestamp,' . + ' time' . ' FROM %s WHERE icao = "%s" AND time>="%s" AND time<"%s" ORDER BY time ASC', - $this->properties['db_metars_arch'], $icao, $time_from, $time_to); + $this->properties['db_metars_arch'], $icao, tms_unix2date($time_from), tms_unix2date($time_to)); } else { /* fetch archived metars from $time_from */ - $query = sprintf('SELECT metar, UNIX_TIMESTAMP(time) AS timestamp, time' . + $query = sprintf('SELECT metar, time AS timestamp, time' . ' FROM %s WHERE icao = "%s" AND time>="%s" ORDER BY time ASC', - $this->properties['db_metars_arch'], $icao,$time_from); + $this->properties['db_metars_arch'], $icao,tms_unix2date($time_from)); } $this->query($query); @@ -275,6 +277,8 @@ else { $metar_array = array(); while($row = $this->fetch_row()) { + $row[1] = tms_date2unix($row[1]); + $row[2] = tms_date2unix($row[2]); $metar_array[] = $row; } } Index: pw_db_null.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/db/pw_db_null.php,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- pw_db_null.php 8 Sep 2003 04:20:44 -0000 1.5 +++ pw_db_null.php 30 Jan 2004 20:46:36 -0000 1.6 @@ -68,7 +68,19 @@ * @access public * @see update_metar() */ - function insert_metar($station, $metar, $timestamp) { + function insert_metar($station, $metar, $timestamp, $time) { + ; + } + + /** + * Pretends to insert an archive METAR into the database. + * + * @param string The ICAO of the station. + * @param string The raw METAR. + * @param integer The time of the report. + * @access public + */ + function insert_metar_arch($icao, $metar, $time) { ; } @@ -81,7 +93,7 @@ * @access public * @see insert_metar() */ - function update_metar($station, $metar, $timestamp) { + function update_metar($station, $metar, $timestamp, $time) { ; } |