Re: pw_images, UTC, TimeZones, LocalTime
Brought to you by:
iridium
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 > > |