Thread: pw_images, UTC, TimeZones, LocalTime
Brought to you by:
iridium
From: Phil P. <phi...@sw...> - 2004-01-05 04:09:37
|
To make pw_images display the correct (day or night) icon, for the moment I've hacked up get_sky_image() as follows /* hacked for Sydney, Summer Time, Phil Pierotti, 04-01-03 */ $metarDST_start = '10310200'; // MMddhhmm $metarDST_end = '03280300'; $metarGMTOffset = 10 ; $metarUsesDST = 1; $metarSunRise = 6; $metarSunSet = 20; if($metarUsesDST) { $todayCheck = date('mdHi'); if(($todayCheck >= $metarDST_start) && ($todayCheck < $metarDST_end)) { $metarDSTOffset = 1; } } else { $metarDSTOffset = 0; } $metarTime = ($regs[2] + $metarGMTOffset + $metarDSTOffset) % 24; if (($metarTime > $metarSunSet) || ($metarTime < $metarSunRise)) { /* ------- */ Realistically, for this to be complete and flexible, each ICAO will need the following information: - TimeZone specified as offset from GMT - uses Daylight Savings? - DST start date - DST end date - latitude & longitude The sunrise and sunset times can be calculated from the information from NOAA http://www.srrb.noaa.gov/highlights/sunrise/calcdetails.html Lat and Long can be had for ICAOs from http://weather.noaa.gov/tg/site.shtml directly -> http://weather.noaa.gov/data/nsd_cccc.txt Enjoy, Phil P |
From: Martin G. <gim...@gi...> - 2004-01-05 15:54:25
|
Phil Pierotti <phi...@sw...> writes: > Realistically, for this to be complete and flexible, each ICAO will > need the following information: > - TimeZone specified as offset from GMT > - uses Daylight Savings? > - DST start date > - DST end date > - latitude & longitude > > The sunrise and sunset times can be calculated from the information > from NOAA http://www.srrb.noaa.gov/highlights/sunrise/calcdetails.html Thanks a lot for that link --- we've made an attempt to implement this kind of functionality before, but when I searched the net I only found some messy algorithms that I didn't have much luck with, see http://makeashorterlink.com/?T162215A2 The information on the above page looks much clearer, and it should be easy to port the JavaScript code to PHP --- those two languages are very much alike. > Lat and Long can be had for ICAOs from > http://weather.noaa.gov/tg/site.shtml directly -> > http://weather.noaa.gov/data/nsd_cccc.txt Thanks again --- I've found those datafiles before, but the information is still not part of PHP Weather. Given the latitude and longitude it should be possible to calculate an approximate timezone. And with that timezone we should be able to give a local time for the reports, but I guess it will still be off by +/- 1 hours depending on daylight saving time, so I don't know how good that idea is. It's just that the real solution: attaching detailed information about the daylight saving time to each station, sounds like a difficult task. But then again, there must be some tables with this information somewhere on every system, so perhaps it's doable? In any case --- I'm having my exams right now! The first one will be on Wednesday, so I wont start playing with this stuff now, but if someone else feels like it, then by all mean do! I can add people to the project as developers if they believe they need CVS access. -- Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather: Shows the current weather on your webpage and PHP Shell: A telnet-connection (almost :-) in a PHP page. |
From: Phil P. <phi...@sw...> - 2004-02-03 20:56:15
|
A little trolling around on the web found me THIS interesting chunk of PHP code: http://www.zend.com/codex.php?id=135&single=1 Specificallly, an implementation of calculating sunrise and set from LAT+LONG+GMT Offset Enjoy, Phil P Martin Geisler wrote: > Phil Pierotti <phi...@sw...> writes: > > >>Realistically, for this to be complete and flexible, each ICAO will >>need the following information: >> - TimeZone specified as offset from GMT >> - uses Daylight Savings? >> - DST start date >> - DST end date >> - latitude & longitude >> >>The sunrise and sunset times can be calculated from the information >>from NOAA http://www.srrb.noaa.gov/highlights/sunrise/calcdetails.html > > > Thanks a lot for that link --- we've made an attempt to implement this > kind of functionality before, but when I searched the net I only found > some messy algorithms that I didn't have much luck with, see > > http://makeashorterlink.com/?T162215A2 > > The information on the above page looks much clearer, and it should be > easy to port the JavaScript code to PHP --- those two languages are > very much alike. > > >>Lat and Long can be had for ICAOs from >>http://weather.noaa.gov/tg/site.shtml directly -> >>http://weather.noaa.gov/data/nsd_cccc.txt > > > Thanks again --- I've found those datafiles before, but the > information is still not part of PHP Weather. Given the latitude and > longitude it should be possible to calculate an approximate timezone. > > And with that timezone we should be able to give a local time for the > reports, but I guess it will still be off by +/- 1 hours depending on > daylight saving time, so I don't know how good that idea is. > > It's just that the real solution: attaching detailed information about > the daylight saving time to each station, sounds like a difficult > task. But then again, there must be some tables with this information > somewhere on every system, so perhaps it's doable? > > > In any case --- I'm having my exams right now! The first one will be > on Wednesday, so I wont start playing with this stuff now, but if > someone else feels like it, then by all mean do! I can add people to > the project as developers if they believe they need CVS access. > |
From: Phil P. <phi...@sw...> - 2004-02-04 01:27:31
|
Here are some of my random thoughts on enabling sunrise/sunset calculations in PHP Weather. Current entries in pw_stations = 5130 Entries from NOAA (http://weather.noaa.gov/data/nsd_cccc.txt) = 6486 - Read the NOAA datafile and update pw_stations - additional fields for LAT and LONG, STATE, ALTITUDE - add records for new STATIONS (1356 new entries) Goal: finding current 'offset from UTC including Daylight Savings if required' for a station Source: the Public Domain TimeZone Database (http://www.twinsun.com/tz/tz-link.htm) As well as being a database of all the timezones including their DST usage zone.tab lists (amongst other things) ISO 3166 2-character country code TimeZone used So, we can match a CC from our stations list to an entry from zone.tab (for speed put the TimeZone into a field in pw_stations) This tells us which timezone to use. In theory, getting the total offset from GMT should then be as simple as $realTZ = getenv('TZ'); putenv ("TZ=$timeZone"); $GMT_offset = date('O'); putenv("TZ=$realTZ"); .... Now we have ICAO Name ISO CC Country Name State Latitude Longitude current GMT offset including DST Grab PHP example code from http://www.zend.com/codex.php?id=135&single=1 I ran a check with co-ords for Sydney, given a hard-coded $DST=1 this code produces data correct to within 10 minutes ie good enough for our uses - tweak code - not calculate DST , just needs $GMT_offset_including_DST - accept co-ordinates as either DMS or decimal (ie auto-convert DMS to decimal) - input params ( GMT DATE, lat, long , local GMT offset including DST ) - returns list($sunriseTimeStamp, $sunsetTimeStamp) - hack code in pw_images.php to identify night_or_day via these calculations Thoughts/comments/suggestions? Phil P Phil Pierotti wrote: > A little trolling around on the web found me THIS interesting chunk of > PHP code: > > http://www.zend.com/codex.php?id=135&single=1 > > Specificallly, an implementation of calculating sunrise and set from > LAT+LONG+GMT Offset > > Enjoy, > Phil P > > > Martin Geisler wrote: > >> Phil Pierotti <phi...@sw...> writes: >> >> >>> Realistically, for this to be complete and flexible, each ICAO will >>> need the following information: >>> - TimeZone specified as offset from GMT >>> - uses Daylight Savings? >>> - DST start date >>> - DST end date >>> - latitude & longitude >>> >>> The sunrise and sunset times can be calculated from the information >>> from NOAA http://www.srrb.noaa.gov/highlights/sunrise/calcdetails.html >> >> >> >> Thanks a lot for that link --- we've made an attempt to implement this >> kind of functionality before, but when I searched the net I only found >> some messy algorithms that I didn't have much luck with, see >> >> http://makeashorterlink.com/?T162215A2 >> >> The information on the above page looks much clearer, and it should be >> easy to port the JavaScript code to PHP --- those two languages are >> very much alike. >> >> >>> Lat and Long can be had for ICAOs from >>> http://weather.noaa.gov/tg/site.shtml directly -> >>> http://weather.noaa.gov/data/nsd_cccc.txt >> >> >> >> Thanks again --- I've found those datafiles before, but the >> information is still not part of PHP Weather. Given the latitude and >> longitude it should be possible to calculate an approximate timezone. >> >> And with that timezone we should be able to give a local time for the >> reports, but I guess it will still be off by +/- 1 hours depending on >> daylight saving time, so I don't know how good that idea is. >> >> It's just that the real solution: attaching detailed information about >> the daylight saving time to each station, sounds like a difficult >> task. But then again, there must be some tables with this information >> somewhere on every system, so perhaps it's doable? >> >> >> In any case --- I'm having my exams right now! The first one will be >> on Wednesday, so I wont start playing with this stuff now, but if >> someone else feels like it, then by all mean do! I can add people to >> the project as developers if they believe they need CVS access. >> > > > > ------------------------------------------------------- > The SF.Net email is sponsored by EclipseCon 2004 > Premiere Conference on Open Tools Development and Integration > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > http://www.eclipsecon.org/osdn > _______________________________________________ > PHPWeather-devel mailing list > PHP...@li... > https://lists.sourceforge.net/lists/listinfo/phpweather-devel > > |
From: Phil P. <phi...@sw...> - 2004-02-21 03:38:55
|
Phil Pierotti wrote: > Here are some of my random thoughts on enabling sunrise/sunset > calculations in PHP Weather. > > Current entries in pw_stations = 5130 > Entries from NOAA (http://weather.noaa.gov/data/nsd_cccc.txt) = 6486 > > - Read the NOAA datafile and update pw_stations > - additional fields for LAT and LONG, STATE, ALTITUDE > - add records for new STATIONS (1356 new entries) Or we could merely leverage the work already done by the developer of AirSort: http://freshmeat.net/projects/airsort/ AirSort uses a MySQL table which includes ICAO, latitude and longitude. GPL, even :-) Enjoy, PhilP |
From: Martin G. <gim...@gi...> - 2004-02-23 10:03:36
|
Phil Pierotti <phi...@sw...> writes: > Phil Pierotti wrote: >> Here are some of my random thoughts on enabling sunrise/sunset >> calculations in PHP Weather. >> Current entries in pw_stations = 5130 >> Entries from NOAA (http://weather.noaa.gov/data/nsd_cccc.txt) = 6486 >> - Read the NOAA datafile and update pw_stations >> - additional fields for LAT and LONG, STATE, ALTITUDE >> - add records for new STATIONS (1356 new entries) I'm sorry that I haven't commented on those ideas before --- I would love to see that implemented! Do you have a SourceForge login? If so, then I would be very happy to add you to the project. > Or we could merely leverage the work already done by the developer > of AirSort: > > http://freshmeat.net/projects/airsort/ > > AirSort uses a MySQL table which includes ICAO, latitude and > longitude. > > GPL, even :-) Uhh... this sounds very interesting! Especially coupled with this email I got the other day: > Hello Martin, > > First thank you for your great PHPWeather script. I think it is very > useful and easy to use. After I found this script, I got the idea of > developing a little weather map for every country (well, currently > it's only Germany *g). So I took a map, figured out the positions of > the weather stations, stored the positions in a database and used > GD-library to put current weather symbols, temperature etc. on this > map. > > If you like to have a look: > http://www.j0nes.de/wetter/ -> this may take a little time to load, > as it has to fetch all the METARs first. > > Cu Jonas It would be very cool to have this functionality in PHP Weather, I've asked Jonas for a SF login so that I can add him to the project. Unfortunately I haven't been that lucky with adding people to the project lately because of strange SF bugs: https://sourceforge.net/tracker/?func=detail&atid=200001&aid=898104&group_id=1 -- Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather: Shows the current weather on your webpage and PHP Shell: A telnet-connection (almost :-) in a PHP page. |
From: Phil P. <phi...@sw...> - 2004-02-24 06:44:02
|
Martin Geisler wrote: > I'm sorry that I haven't commented on those ideas before --- I would > love to see that implemented! Do you have a SourceForge login? If so, > then I would be very happy to add you to the project. I do have a login (somewhere, just need to find it again), though I would suggest you hold of on adding me to the project just yet. So far I've been simply looking into the requirements and issues behind adding this kind of functionality. I've even done most of the work modifying sunrise/sunset calculations into a PHP function (probably needs a few 'neatness' type cleanups {eg auto-convert DMS to degrees}, but it works). function calc_SunriseSunset($date (=timestamp), $timezone (=hours from GMT, inc DST), $latitude (as decmal), $longitude (as decimal)) {} returns an array being sunrise-timestamp, sunset-timestamp On any page on my website (http://home.swiftdsl.com.au/~Phil.Pierotti/), there's a 'widget' showing the weather (icons) for Sydney (Australia) as extracted by PHPWeather. If you 'mouseover' the (details) link, a DHTML popup (via overLib, see my credits page) in the window will show you the full report. The last line in said detail report uses the rise/set times as calculated by this function. The other day I started looking at the PHPWeather code itself (spefically, to integrate calc_SunriseSunset into day/night evaluation for images) , and my initial (ten second) analysis was along the lines of "this will be non-trivial" (mainly due to my lack of familiarity with the code , and being relatively new to PHP programming). Basically, I was hoping there was someone more familiar with the PHPWeather code who was interested in running with this now that I've gotten some of the basics started. >>Or we could merely leverage the work already done by the developer >>of AirSort: >> >> http://freshmeat.net/projects/airsort/ >> >>AirSort uses a MySQL table which includes ICAO, latitude and >>longitude. >> >>GPL, even :-) I spent yesterday playing around with AirSort and integrated it with the PHPWeather driven page on my site (though it's not 'live', currently only on my private test server - I could post a small trimmed screenshot for the impatient). The biggest hassle I had was that (I think due to some CSS thing I'd done) IE wanted to not draw the table properly (for the empty cells below the point), so the pinpointing was incorrect. Adding in explicit heights for the table cell below the point fixed it. I've also tweaked it for both 'large'(800x400) and 'small' (400x200) maps (and made small maps from the existing large ones). Still need to finish a few more minor 'flexibility' type changes, but it works nicely. From my basic testing, I suspect some of the co-ordinates are off, and several of the ICAOs from PHPWeather don't have entries in the AirSort table. Obviously some data-cleanups due here. So at this point I'm looking to tackle the AirSort flexibility cleanups, and data correctness. Once that's done I'll look at more work on the PHPWeather Lat/Long&Rise/Set issue (since I'll have clean data to work with); however, as I mentioned earlier, it will probably be better (or at least faster) handled by someone who is already familiar with the code. Phil P |
From: Martin G. <gim...@gi...> - 2004-02-24 13:29:47
|
Phil Pierotti <phi...@sw...> writes: > Martin Geisler wrote: > >> I'm sorry that I haven't commented on those ideas before --- I >> would love to see that implemented! Do you have a SourceForge >> login? If so, then I would be very happy to add you to the >> project. > > I do have a login (somewhere, just need to find it again), though I > would suggest you hold of on adding me to the project just yet. Well... I've always tried to attract people to the project in an attempt to stimulate growth. I can see that I've not spend that much time on PhpWeather lately --- I wasn't even the guy making the latest release (Etienne did that, thanks!) so I now try to make it easy for other people to get involved. > [... lots of experiments with sunrice/set and airsort ...] That sound very promissing! I'm sure we'll find a way of integrating this functionality. -- Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather: Shows the current weather on your webpage and PHP Shell: A telnet-connection (almost :-) in a PHP page. |