Line 524... |
Line 524... |
#endif //INCLUDE_QSORT
|
#endif //INCLUDE_QSORT
|
|
|
|
|
#ifdef INCLUDE_TIMELIB
|
#ifdef INCLUDE_TIMELIB
|
/************************* time.h ***********************/
|
/************************* time.h ***********************/
|
/* Day light savings first Sunday in April and last Sunday in October
|
|
is_dst means hour has been compensated for day light savings
|
|
leap year if year divisible by 4. Centenary years should only be
|
|
leap-years if they were divisible by 400. */
|
|
#define SEC_PER_YEAR (365L*24*60*60)
|
#define SEC_PER_YEAR (365L*24*60*60)
|
#define SEC_PER_DAY (24L*60*60)
|
#define SEC_PER_DAY (24L*60*60)
|
//typedef unsigned long time_t; //start at 1/1/80
|
//typedef unsigned long time_t; //start at 1/1/80
|
//struct tm {
|
//struct tm {
|
// int tm_sec; //(0,59)
|
// int tm_sec; //(0,59)
|
Line 540... |
Line 536... |
// int tm_mday; //(1,31)
|
// int tm_mday; //(1,31)
|
// int tm_mon; //(0,11)
|
// int tm_mon; //(0,11)
|
// int tm_year; //(0,n) from 1900
|
// int tm_year; //(0,n) from 1900
|
// int tm_wday; //(0,6) calculated
|
// int tm_wday; //(0,6) calculated
|
// int tm_yday; //(0,365) calculated
|
// int tm_yday; //(0,365) calculated
|
// int tm_isdst; // calculated
|
// int tm_isdst; //hour adjusted for day light savings
|
//};
|
//};
|
static const unsigned short DaysUntilMonth[]=
|
static const unsigned short DaysUntilMonth[]=
|
{0,31,59,90,120,151,181,212,243,273,304,334,365};
|
{0,31,59,90,120,151,181,212,243,273,304,334,365};
|
static const unsigned short DaysInMonth[]=
|
static const unsigned short DaysInMonth[]=
|
{31,28,31,30,31,30,31,31,30,31,30,31};
|
{31,28,31,30,31,30,31,31,30,31,30,31};
|
static time_t DstTimeIn, DstTimeOut;
|
static time_t DstTimeIn, DstTimeOut;
|
|
|
|
|
|
/* Leap year if divisible by 4. Centenary years should only be
|
|
leap-years if they were divisible by 400. */
|
static int IsLeapYear(int year)
|
static int IsLeapYear(int year)
|
{
|
{
|
return(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
|
return(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
|
}
|
}
|
|
|
Line 562... |
Line 561... |
|
|
days = tp->tm_mday - 1 + DaysUntilMonth[tp->tm_mon] +
|
days = tp->tm_mday - 1 + DaysUntilMonth[tp->tm_mon] +
|
365 * (tp->tm_year - 80);
|
365 * (tp->tm_year - 80);
|
seconds = (unsigned long)tp->tm_sec + 60L * (tp->tm_min +
|
seconds = (unsigned long)tp->tm_sec + 60L * (tp->tm_min +
|
60L * (tp->tm_hour + 24L * days));
|
60L * (tp->tm_hour + 24L * days));
|
|
if(tp->tm_isdst)
|
|
seconds -= 60 * 60;
|
year = 1900 + tp->tm_year - (tp->tm_mon < 2);
|
year = 1900 + tp->tm_year - (tp->tm_mon < 2);
|
for(y = 1980; y <= year; y += 4)
|
for(y = 1980; y <= year; y += 4)
|
{
|
{
|
if(y % 100 != 0 || y % 400 == 0)
|
if(y % 100 != 0 || y % 400 == 0)
|
seconds += SEC_PER_DAY;
|
seconds += SEC_PER_DAY;
|
Line 581... |
Line 582... |
unsigned long year, month;
|
unsigned long year, month;
|
|
|
out->tm_isdst = 0;
|
out->tm_isdst = 0;
|
if(DstTimeIn <= secondsIn && secondsIn < DstTimeOut)
|
if(DstTimeIn <= secondsIn && secondsIn < DstTimeOut)
|
{
|
{
|
secondsIn -= 60 * 60;
|
secondsIn += 60 * 60;
|
out->tm_isdst = 1;
|
out->tm_isdst = 1;
|
}
|
}
|
seconds = secondsIn;
|
seconds = secondsIn;
|
for(year = 0; ; ++year)
|
for(year = 0; ; ++year)
|
{
|
{
|
Line 623... |
Line 624... |
}
|
}
|
|
|
|
|
void gmtimeDst(time_t dstTimeIn, time_t dstTimeOut)
|
void gmtimeDst(time_t dstTimeIn, time_t dstTimeOut)
|
{
|
{
|
/*DST from first Sunday in April to last Sunday in October at 2am*/
|
|
DstTimeIn = dstTimeIn;
|
DstTimeIn = dstTimeIn;
|
DstTimeOut = dstTimeOut;
|
DstTimeOut = dstTimeOut;
|
}
|
}
|
|
|
|
|
|
//DST from 2am on the second Sunday in March to 2am first Sunday in November
|
|
void gmtimeDstSet(time_t *tp, time_t *dstTimeIn, time_t *dstTimeOut)
|
|
{
|
|
time_t seconds, timeIn, timeOut;
|
|
struct tm tmDate;
|
|
int year, days;
|
|
|
|
DstTimeIn = 0;
|
|
DstTimeOut = 0;
|
|
gmtime_r(tp, &tmDate);
|
|
year = tmDate.tm_year;
|
|
|
|
//March 1, year, 2AM -> second Sunday
|
|
tmDate.tm_year = year;
|
|
tmDate.tm_mon = 2;
|
|
tmDate.tm_mday = 1;
|
|
tmDate.tm_hour = 2;
|
|
tmDate.tm_min = 0;
|
|
tmDate.tm_sec = 0;
|
|
seconds = mktime(&tmDate);
|
|
gmtime_r(&seconds, &tmDate);
|
|
days = 7 - tmDate.tm_wday + 7;
|
|
*dstTimeIn = timeIn = seconds + days * SEC_PER_DAY;
|
|
|
|
//November 1, year, 2AM -> first Sunday
|
|
tmDate.tm_year = year;
|
|
tmDate.tm_mon = 10;
|
|
tmDate.tm_mday = 1;
|
|
tmDate.tm_hour = 2;
|
|
tmDate.tm_min = 0;
|
|
tmDate.tm_sec = 0;
|
|
seconds = mktime(&tmDate);
|
|
gmtime_r(&seconds, &tmDate);
|
|
days = 7 - tmDate.tm_wday;
|
|
*dstTimeOut = timeOut = seconds + days * SEC_PER_DAY;
|
|
|
|
DstTimeIn = timeIn;
|
|
DstTimeOut = timeOut;
|
|
}
|
#endif //INCLUDE_TIMELIB
|
#endif //INCLUDE_TIMELIB
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|