Re: Calculating daylight savings time
| From: | Micah Stevens | Date: | Wed, 20 Aug 2003 15:53:14 +0000 |
| Subject: | Re: Calculating daylight savings time | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-29989@lists.php.net to get a copy of this message | ||
It tells PHP which way to format various locale specific functions. (date
stuff, money stuff, etc..)
-Micah
On Wednesday 20 August 2003 2:23 am, Lisi wrote:
> I saw it, at first I didn't think it would work but it's great - just what
> I need. I guess I was just surprised that there isn't an easier way to do
> this in PHP by switching from the default. I also like to write my own code
> rather than use someone else's, since it's the best way to learn, but in
> this case it wasn't worth rewriting this function from scratch since it
> does exactly what I need.
>
> I'm still confused though about setlocale - what does this do in plain
> English?
>
> Thanks for the info,
>
> -Lisi
>
> At 10:05 AM 8/19/03 -0700, Micah Stevens wrote:
> >Here's the example code I was talking about in the docs, you should really
> >read the user submitted notes in the docs, they're very helpful, moreso
> > than the docs from time to time.
> >
> >(this is not my code..)
> >
> >leafrink at hotmail dot com
> > 28-Feb-2003 07:26
> >
> >
> >
> >Wrote this function after a fair bit of searching on the subject.
> >Don't know if it's the best way to do it, but it works.
> >
> >Its not that exact but it's pretty close.
> >
> >Hope it helps someone out there.
> >
> >/**
> >* function for working out if it is daylight savings for a specific date.
> >* must specify when daylight savings starts and ends in the format
> >* "[1=First,2=Second,3=Third,4=Fourth,L=Last]:NameOfDay:Of The Month"
> >* e.g. "L:Sun:3" = Last Sunday in March
> >* some will not meet this criteria but most do.
> >*
> >* see - http://webexhibits.org/daylightsaving/g.html for
> >daylight savings
> >times around the world.
> >*
> >*/
> >function is_daylight_savings($gmtime,$DSTStart = '',$DSTEnd = ''){
> > //global $locale;
> > //For Most Of Australia
> > //DayLightSavings Starts Last sunday in October
> > $DSTStart = "L:Sun:10";//$locale['DSTStart'];
> > //DayLightSavings Ends Last Sunday in March
> > $DSTEnd = "L:Sun:3";//$locale['DSTEnd'];
> >
> > $DSTStart = split(":",$DSTStart);
> > $DSTEnd = split(":",$DSTEnd);
> >
> > $gmtMonth = date("n",$gmtime);
> > // if not even in the Important changeover months.
> > if ($gmtMonth < $DSTStart[2] && $gmtMonth > $DSTEnd[2]){
> > return false;
> > } else if ($gmtMonth > $DSTStart[2] || $gmtMonth < $DSTEnd[2]) {
> > return true;
> > } else {
> > //it is in the Start or End Month
> > if ($gmtMonth == $DSTStart[2]){
> > $True = true;
> > $week = $DSTStart[0];
> > $ImportantDay = $DSTStart[1];
> > } else {//it is in the End Month
> > $True = false;
> > $week = $DSTEnd[0];
> > $ImportantDay = $DSTEnd[1];
> > }
> > //get the day of the month
> > $gmtDay = date("j",$gmtime);
> > //work out what week it starts/ends.
> > if ($week == 'L'){
> > $week = 4;
> > $ldom = 4;//last day of month factor
> > }
> > //if the week in which it starts/ends has not been reached
> > if($gmtDay < ($week-1)*7){
> > return (!$True);
> > } else {
> > $gmtDate = getdate($gmtime);
> > //go by a Day of the Week Basis
> > for ($i=($week-1)*7;$i<(($week*7)+$ldom);$i++){
> > $checkDate =
> > mktime(0,0,0,$gmtDate["mon"],$i,$gmtDate["year"]);
> > //get the actual day it starts/ends
> > if (date("D",$checkDate) == "Sun" &&
> > date("n",$checkDate) ==
> > $gmtMonth
> >){
> > $day = date("j",$checkDate);
> > }
> > }
> > if ($gmtDay < $day) {//if it has not reached the day
> > return (!$True);
> > } else {
> > return $True;
> > }
> > }
> > }
> >}
> >
> >//Testing
> >if(is_daylight_savings(strtotime("26-Oct-2003"))){
> > echo "is DAYLIGHT SAVINGS";
> >}else {
> > echo "is NOT DAYLIGHT SAVINGS";
> >}
> >
> >On Tuesday 19 August 2003 2:37 am, Lisi wrote:
> > > What I need to do is figure this out for more than one location at a
> > > time. I am displaying Sabbath times for several different cities around
> > > the world at once (New York, London, Paris, Jerusalem, Sydney) - i.e. a
> > > certain amount of time before sunset, different for each city and each
> > > city is in a different dst zone.
> > >
> > > Can I do something using setlocale, to change timezones to the city I
> > > need, and then use date(I)? Or does date(I) always work only for the
> > > US? And what exactly does setlocale change? I couldn't figure out from
> > > the notes on php.net.
> > >
> > > Thanks for your help,
> > >
> > > -Lisi
> > >
> > > At 12:06 AM 8/17/03 -0700, Micah Stevens wrote:
> > > >As an afterthought, the docs are inspecific on who's daylight savings
> > > >schedule
> > > >that the function returns. There's another user submitted function in
> > > > the comments list that takes into account a specific schedule.
> > > >
> > > >-Micah
> > > >
> > > >On Sunday 17 August 2003 12:43 am, Lisi wrote:
> > > > > I have sunset times stored in a database and the a PHP page that
> > > > > performs a number of calculations on the retrieved time. One of the
> > > > > things I need to figure out is whether or not to add an hour for
> > > > > Daylight Savings Time. Since there is more than once location, and
> > > > > each one begins and ends DST at a different time, I need to figure
> > > > > this out based on location. My question is, how do I figure out
> > > > > whether it's the "first sunday in April" yet or not? I know
> > > > > it has
> > > > > to do with the date() function somehow, I'm just not sure how to
> > > > > use it properly in this case - any suggestions?
> > > > >
> > > > > Thanks,
> > > > >
> > > > > -Lisi
> >
> >--
> >PHP Database Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php