Timezone offsets (and st/dst changes) in MySQL / PHP -
basically have site allows stores store open/close times.
now, i'm trying add feature of giving visitors ability see if store closed.
i understand can run query like:
select * `store_hours` time(now()) between `opens` , `closes`
... , query works , retrieves stores open. however, @ first query didn't put consideration store's timezone.
so.. decided store store's open/close times conversion utc attached:
id | store_id | opens | closes | utc_opens | utc_closes
now can query so:
select * `store_hours` time(now()) between `utc_opens` , `utc_closes`
so can global list of how many stores open , doesn't matter are.
now came problem. through php, did add offset timestamp:
date('h:i', strtotime($values['closes']) + $offset)
then started thinking pacific standard time , daylight savings time.
i want add open/close feature , become huge part of system. it's lose out on lot of income if i'm off hour.
i've never dealt before (nor ever wish to, because it's annoyingly complex problem). said, there methods around this:
it seems if want system work not perfectly, pretty damn well, have dive this:
http://en.wikipedia.org/wiki/zoneinfo
in short, problem 1 of granular complexity. no matter how hard try, can't write simple script determine store's exact time given static gmt offset. overcome issue, people have put public databases account (nearly) of little nooks , crannies inherent in time zones. if know user in western (west of rockies), don't know if he's in barstow or phoenix (arizona doesn't dst, half year it's got same time la, , other half it's same denver).
so data entry go...you need put in exact time zone code each store , query zoneinfo database determine current offset should be.
Comments
Post a Comment