Fuction to calculate Daylight Savings Time Start & End

From: Date: Mon, 03 Jul 2000 07:09:56 +0000
Subject: Fuction to calculate Daylight Savings Time Start & End
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-23272@lists.php.net to get a copy of this message
Here's some code, although quite simple, I found useful. Perhaps someone else might... // DST - functions to return start and end of Daylight Savings Time // David G.Powers - DavidGPowers@PSSP.com #include "php.h" #include "php_calendar.h" #include <time.h> //////////////////////////////////////////////////////////////////////////// / PHP_FUNCTION(getdststart) { pval *year_arg; long year; time_t the_time; struct tm *ta, April; // get the year to work with switch(ARG_COUNT(ht)) { // default to current year if none passed case 0: the_time = time(NULL); ta = localtime(&the_time); year = ta->tm_year; break; // get year passed in case 1: if ( getParameters(ht, 1, &year_arg) == FAILURE ) { WRONG_PARAM_COUNT; } convert_to_long(year_arg); year = year_arg->value.lval; // time.h functions use years since 1900 // if passed as CCYY then adjust accordingly // otherwise assume passes as year since 1900 if (year > 1900) year -= 1900; break; default: WRONG_PARAM_COUNT; } // verify year is within range 1970 - 2037 if ( year < 70 || year > 137 ) { php_error(E_WARNING, "The getdststart() function is only valid for years between 1970 and 2037 inclusive"); RETURN_FALSE; } // find start of DST (2:00am on first Sunday of April) // get April 1st April.tm_sec = 0; April.tm_min = 0; April.tm_hour = 2; April.tm_mday = 1; April.tm_mon = 3; April.tm_year = year; the_time = mktime(&April); if ( April.tm_wday ) { April.tm_mday += (7 - April.tm_wday); the_time = mktime(&April); } return_value->value.lval = the_time; return_value->type = IS_LONG; } /////////////////////////////////////////////////////////////// PHP_FUNCTION(getdstend) { pval *year_arg; long year; time_t the_time; struct tm *ta, October; // get the year to work with switch(ARG_COUNT(ht)) { // default to current year if none passed case 0: the_time = time(NULL); ta = localtime(&the_time); year = ta->tm_year; break; // get year passed in case 1: if ( getParameters(ht, 1, &year_arg) == FAILURE ) { WRONG_PARAM_COUNT; } convert_to_long(year_arg); year = year_arg->value.lval; // time.h functions use years since 1900 // if passed as CCYY then adjust accordingly // otherwise assume passes as year since 1900 if (year > 1900) year -= 1900; break; default: WRONG_PARAM_COUNT; } // verify year is within range 1970 - 2037 if ( year < 70 || year > 137 ) { php_error(E_WARNING, "The getdstend() function is only valid for years between 1970 and 2037 inclusive"); RETURN_FALSE; } // find start of DST (2:00am on last Sunday of October) // get October 31st October.tm_sec = 0; October.tm_min = 0; October.tm_hour = 2; October.tm_mday = 31; October.tm_mon = 9; October.tm_year = year; the_time = mktime(&October); if ( October.tm_wday ) { October.tm_mday -= October.tm_wday; the_time = mktime(&October); } return_value->value.lval = the_time; return_value->type = IS_LONG; }

« previous php.dev (#23272) next »