Jump to content

Daylight savings time problem


luchosoto

Recommended Posts

Hi all!!

I've got a bit of a problem and I think you people can help me.

I'm using a daylight savings script I found, and I adapted it so that it adjusts the time in my country (Chile). The issue is that the script is set to switch to DST starting on the last Sunday in October until the first Sunday of April.

The DST in Chile starts on the second Sunday in October until the second Sunday of March.

 

here's the full code:

$calc_adjust = 0; // set time to make change
$time_regulr = 3600;    // set regular time offset
$time_DSTadj = 7200; // set DST time offset
$varble_name = "adjust_DST"; // set varialbe name

$mnth_server = date("n", time() + $calc_adjust);
$dayw_server = date("w", time() + $calc_adjust);
$date_server = date("j", time() + $calc_adjust);

if ($mnth_server >= 4 && $mnth_server <= 9) {
  $$varble_name = $time_regulr; // Regular Time
} else {
  if ($mnth_server <= 2 || $mnth_server >= 11) {
    $$varble_name = $time_DSTadj; // DST
  } else {
    if (($mnth_server == 3 && $date_server - $dayw_server <= 0 ) || ($mnth_server == 10 && $date_server - $dayw_server >= 25 )) {
      $$varble_name = $time_regulr; // Regular Time
    } else {
      $$varble_name = $time_DSTadj; // DST
    }
  }
}

echo date("l, F j, Y, g:i A",time() + $$varble_name);

 

How can I fix this line in order to work according to my local DST rules??

 if (($mnth_server == 3 && $date_server - $dayw_server <= 0 ) || ($mnth_server == 10 && $date_server - $dayw_server >= 25 ))

 

Any suggestions or solutions are welcome.

Thanx in advance!!!

Link to comment
https://forums.phpfreaks.com/topic/52385-daylight-savings-time-problem/
Share on other sites

Instead of using a dodgy offset, why not let PHP do all the work for you? I'm sure this code will include the DST stuff:

 

<?php

ini_set("date.timezone", "Chile/Continental");

// If that doesn't work, use this:

date_default_timezone_set("Chile/Continental");

/* Now put the rest of your code here */

?>

 

Timezones : http://www.php.net/manual/en/timezones.php

 

(Chile/EasterIsland is also available)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.