Re: [PHP] Daylight Savings Time in PHP4

2007-01-18 Thread Andrew Kreps

On 1/18/07, mike caplin [EMAIL PROTECTED] wrote:

Does anyone know if the change in Daylight Savings Time (March this year)
affects PHP v4.x?  I looked around www.php.net and all I could find was a
reference to v5 (http://bugs.php.net/bug.php?id=35296).  Is there a v4
release which is compatible with the DST change?  Or even a patch could be
applied?



I've been using PHP for a lot of years, and I've never had a
time-change issue.  I don't think PHP cares what time it is.  When the
time changes, your logs might look a little funny, but it will keep on
chugging.

Now, that doesn't mean that all of your *code* is time-change safe.
Nor does it mean that your system handles the time change properly.  I
can't imagine that PHP itself would cause any issues.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DAYLIGHT SAVINGS TIME OR NOT

2004-07-20 Thread PHPDiscuss - PHP Newsgroups and mailing lists
You could also use the php date() function.

date('I');  

If you need it for a specific date, then
date('I',$timestamp);



Curt Zirzow wrote:

 * Thus wrote Chirag Shukla:
  
  This function can be used to know whether it is Daylight Savings time or 
  not for the given date. It may not be the most optimized program, but 
  may be helpful.
  
  If there is a modified code, please let me know.

 ok.


  
  ?php
  
  // here is the date. We wont worry about the time.
  $processdate = 07/04/2004 14:45;

 What about different formats like 07-04-2004 14:45:00

  
  // calling the function.
  // 1 means the date is in a daylight savings time
  // 0 means the date is not in a daylight savings time

  one thing to note, not all zones, even in the US honor the
  DST. this is a rather sepecific function.

  echo daylight($processdate);
  
  // now the function
  
  function daylight($mydate)
  {
  // separating the date and time
  $datetime = explode( ,$mydate);
  
  // exploding the components of date
  $dateexplode = explode(/,$datetime[0]);

  Instead of exploding stuff around, make your date argument compatible
  with the strtotime() function, it will return a unix timestamp or
  -1 if it fails to parse the date.


  
  // if the date is between Jan-Mar, NO DAYLIGHT
  // if the date is between Nov-Dec, NO DAYLIGHT
  if ($dateexplode[0]4 or $dateexplode[0]10)
  {
  return 0;
  }
  // if the date is not in the above zone, lets see
  // if the date is between May-Sep, DAYLIGHT
  elseif ($dateexplode[0]4 and $dateexplode[0]10)
  {
  return 1;
  }

   Since you have a timestamp as I suggested above, you simply need
   to pull the month out, and then check the month value:

   $month = strftime('%m', $utimestamp);

   swtich ($month) {
 case '01': case '02': ...
return 0;
 case '05': case '06': ...
return 1;

   }


  else
  {
  // we are going to pull out what date is a sunday
  // then we compare our date's day-of-month with the 
  day-that-is-sunday
  
  $interestday = 0;
  
  // lets see what happens in april - first sunday of the month
  if ($dateexplode[0]==4)
  {
  // looping the first seven days to see what day is a 
  sunday
  for ($i=1; $i=7; $i++)
  {
  $myday = 
  
  date(w,mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2]));
  if ($myday==0)
  $interestday = $i;
  }
  
  // now that we got what day is a sunday, lets see
  // if our date's day-of-month is greater than this 
  or not
  // if it is greater, then DAYLIGHT
  if ($dateexplode[1]=$interestday)
  return 1;
  else
  return 0;
  }
  
  // lets see what happens in october - last sunday of the 
  month
  elseif ($dateexplode[0]==10)
  {
  // looping the first seven days to see what day is a 
  sunday
  for ($i=25; $i=31; $i++)
  {
  $myday = 
  
  date(w,mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2]));
  if ($myday==0)
  $interestday = $i;
  }
  
  // now that we got what day is a sunday, lets see
  // if our date's day-of-month is greater than this 
  or not
  // if it is less, then DAYLIGHT
  if ($dateexplode[1]=$interestday)
  return 1;
  else
  return 0;
  }
  }

   now instead of doing all that mundane work, we simply have to
   find out if the  days are outabounds for the paticular months.

   // obtain the day of month 
   $dayofmonth = (int)strftime('%d', $utimestamp);

   // and the day of week
   $dayofweek =  strftime('%u', $utimestamp);

   if ($month == '04') {

 // If its the first week of 04
 if ($dayofmonth = 7) {

   // and we havn't reached sunday, return 0
   return ($dayofweek  7) ? 0: 1;

 }
 return 1; // otherwise we're passed it.

   } elseif ($month == '10') {

 // look at the last week october
 if ($dayofmonth = 24) {

   // see if we're still in the zone.
   return ($dayofweek  7) ? 1: 0;
 }
 return 1;

   }

   // something went wrong.
   

Re: [PHP] DAYLIGHT SAVINGS TIME OR NOT

2004-07-14 Thread Chirag Shukla

?php
// here is the date. We wont worry about the time.
$processdate = 07/04/2004 14:45;

What about different formats like 07-04-2004 14:45:00
...You have a good point, Curt. We could modify the code just a little 
bit for the same then. Instead of exploding with /, we may opt for - 
explosion. Typically, I have observed users using one specific format 
for their entire application. A simple change in the function can make 
the function suit their requirements.


// calling the function.
// 1 means the date is in a daylight savings time
// 0 means the date is not in a daylight savings time

 one thing to note, not all zones, even in the US honor the
 DST. this is a rather sepecific function.
...I believe Indiana and Arizona do not honor daylight savings time. 
They switch back and forth from EST to CST (Indiana) and MST to PST 
(Arizona) if I am not mistaken. If it is not applicable to a particular 
user(s), they should not use this function. This function could be 
useful for only those who intend to use it.


echo daylight($processdate);
// now the function
function daylight($mydate)
{
// separating the date and time
$datetime = explode( ,$mydate);
// exploding the components of date
$dateexplode = explode(/,$datetime[0]);

 Instead of exploding stuff around, make your date argument compatible
 with the strtotime() function, it will return a unix timestamp or
 -1 if it fails to parse the date.
...Good point. I should write something with strtotime(). Thank you.


// if the date is between Jan-Mar, NO DAYLIGHT
// if the date is between Nov-Dec, NO DAYLIGHT
if ($dateexplode[0]4 or $dateexplode[0]10)
{
return 0;
}
// if the date is not in the above zone, lets see
// if the date is between May-Sep, DAYLIGHT
elseif ($dateexplode[0]4 and $dateexplode[0]10)
{
return 1;
}

  Since you have a timestamp as I suggested above, you simply need
  to pull the month out, and then check the month value:
...I used the above method to indicate to users what is going on. I did 
not use switch :: case because I did not want a month-to-month checking. 
I wanted to check and process for only months 4 through 10 and for only 
those dates in month 4  10 that made a difference between CST and CDT 
(or any time zone change, in that case).


  $month = strftime('%m', $utimestamp);
  
  swtich ($month) {
case '01': case '02': ...
   return 0;
case '05': case '06': ...
   return 1;
   
  }


	else
	{
		// we are going to pull out what date is a sunday
		// then we compare our date's day-of-month with the 
		day-that-is-sunday
		
		$interestday = 0;
		
		// lets see what happens in april - first sunday of the month
		if ($dateexplode[0]==4)
		{
			// looping the first seven days to see what day is a 
			sunday
			for ($i=1; $i=7; $i++)
			{
$myday = 
date(w,mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2]));
if ($myday==0)
	$interestday = $i;
			}
			
			// now that we got what day is a sunday, lets see
			// if our date's day-of-month is greater than this 
			or not
			// if it is greater, then DAYLIGHT
			if ($dateexplode[1]=$interestday)
return 1;
			else
return 0;
		}

		// lets see what happens in october - last sunday of the 
		month
		elseif ($dateexplode[0]==10)
		{
			// looping the first seven days to see what day is a 
			sunday
			for ($i=25; $i=31; $i++)
			{
$myday = 
date(w,mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2]));
if ($myday==0)
	$interestday = $i;
			}
			
			// now that we got what day is a sunday, lets see
			// if our date's day-of-month is greater than this 
			or not
			// if it is less, then DAYLIGHT
			if ($dateexplode[1]=$interestday)
return 1;
			else
return 0;
		}
	}
  
  now instead of doing all that mundane work, we simply have to
  find out if the  days are outabounds for the paticular months.
...Your code looks neater. Thank you.

  // obtain the day of month 
  $dayofmonth = (int)strftime('%d', $utimestamp);

  // and the day of week
  $dayofweek =  strftime('%u', $utimestamp);
  if ($month == '04') {
// If its the first week of 04
if ($dayofmonth = 7) {
  // and we havn't reached sunday, return 0
  return ($dayofweek  7) ? 0: 1;
}
return 1; // otherwise we're passed it.
   
  } elseif ($month == '10') {

// look at the last week october
if ($dayofmonth = 24) {
   
  // see if we're still in the zone.
  return ($dayofweek  7) ? 1: 0;
}
return 1;

  }
  // something went wrong.
  return -2;

}

Curt
...Thanks for your comments, Curt. Whenever I write a better code, I 
will post it here.

Chirag Shukla.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] DAYLIGHT SAVINGS TIME OR NOT

2004-07-13 Thread Curt Zirzow
* Thus wrote Chirag Shukla:
 
 This function can be used to know whether it is Daylight Savings time or 
 not for the given date. It may not be the most optimized program, but 
 may be helpful.
 
 If there is a modified code, please let me know.

ok.


 
 ?php
 
   // here is the date. We wont worry about the time.
   $processdate = 07/04/2004 14:45;

What about different formats like 07-04-2004 14:45:00

 
   // calling the function.
   // 1 means the date is in a daylight savings time
   // 0 means the date is not in a daylight savings time

 one thing to note, not all zones, even in the US honor the
 DST. this is a rather sepecific function.

   echo daylight($processdate);
 
   // now the function
 
 function daylight($mydate)
 {
   // separating the date and time
   $datetime = explode( ,$mydate);
 
   // exploding the components of date
   $dateexplode = explode(/,$datetime[0]);

 Instead of exploding stuff around, make your date argument compatible
 with the strtotime() function, it will return a unix timestamp or
 -1 if it fails to parse the date.


 
   // if the date is between Jan-Mar, NO DAYLIGHT
   // if the date is between Nov-Dec, NO DAYLIGHT
   if ($dateexplode[0]4 or $dateexplode[0]10)
   {
   return 0;
   }
   // if the date is not in the above zone, lets see
   // if the date is between May-Sep, DAYLIGHT
   elseif ($dateexplode[0]4 and $dateexplode[0]10)
   {
   return 1;
   }

  Since you have a timestamp as I suggested above, you simply need
  to pull the month out, and then check the month value:

  $month = strftime('%m', $utimestamp);
  
  swtich ($month) {
case '01': case '02': ...
   return 0;
case '05': case '06': ...
   return 1;
   
  }


   else
   {
   // we are going to pull out what date is a sunday
   // then we compare our date's day-of-month with the 
   day-that-is-sunday
   
   $interestday = 0;
   
   // lets see what happens in april - first sunday of the month
   if ($dateexplode[0]==4)
   {
   // looping the first seven days to see what day is a 
   sunday
   for ($i=1; $i=7; $i++)
   {
   $myday = 
   
 date(w,mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2]));
   if ($myday==0)
   $interestday = $i;
   }
   
   // now that we got what day is a sunday, lets see
   // if our date's day-of-month is greater than this 
   or not
   // if it is greater, then DAYLIGHT
   if ($dateexplode[1]=$interestday)
   return 1;
   else
   return 0;
   }
 
   // lets see what happens in october - last sunday of the 
   month
   elseif ($dateexplode[0]==10)
   {
   // looping the first seven days to see what day is a 
   sunday
   for ($i=25; $i=31; $i++)
   {
   $myday = 
   
 date(w,mktime(0,0,0,$dateexplode[0],$i,$dateexplode[2]));
   if ($myday==0)
   $interestday = $i;
   }
   
   // now that we got what day is a sunday, lets see
   // if our date's day-of-month is greater than this 
   or not
   // if it is less, then DAYLIGHT
   if ($dateexplode[1]=$interestday)
   return 1;
   else
   return 0;
   }
   }
  
  now instead of doing all that mundane work, we simply have to
  find out if the  days are outabounds for the paticular months.

  // obtain the day of month 
  $dayofmonth = (int)strftime('%d', $utimestamp);

  // and the day of week
  $dayofweek =  strftime('%u', $utimestamp);

  if ($month == '04') {

// If its the first week of 04
if ($dayofmonth = 7) {

  // and we havn't reached sunday, return 0
  return ($dayofweek  7) ? 0: 1;

}
return 1; // otherwise we're passed it.
   
  } elseif ($month == '10') {

// look at the last week october
if ($dayofmonth = 24) {
   
  // see if we're still in the zone.
  return ($dayofweek  7) ? 1: 0;
}
return 1;

  }

  // something went wrong.
  return -2;


 }


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes

Re: [PHP] daylight savings time ?

2003-04-01 Thread Peter Houchin
my understanding it that PHP uses the time  date on your server ... so 
there for I'd be thinking that maybe the time /or date on your server 
is wrong.. so update the clock on the server

Heather P wrote:
Hello.
I use a forum which has the time as the coding (D M d, Y g:i a) how do I 
add an hour for daylight savings time ? I live in the uk and the time on 
the forum is wrong. how do I change it  ? Thanks

_
Overloaded with spam? With MSN 8, you can filter it out 
http://join.msn.com/?page=features/junkmailpgmarket=en-gbXAPID=32DI=1059




--

Peter Houchin
Sun Rentals STR Manager
Phone: 03 9869 6452
Fax:   03 9866 2511
Mobile:0438 789 220
[EMAIL PROTECTED]
http://www.sunrentals.com.au/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] daylight savings time ?

2003-04-01 Thread Don Read

On 02-Apr-2003 Heather P wrote:
 Hello.
 I use a forum which has the time as the coding (D M d, Y g:i a) how do I
 add 
 an hour for daylight savings time ? I live in the uk and the time on the 
 forum is wrong. how do I change it  ? Thanks
 

Assuming you wrote the scripts (rather than you just use it) then add
 putenv('TZ=GMT0BST'); at the start oof each script.

Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php