 | Discussion Forum |  |
|
|
Dayligh saving time CodeNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Zal Nawaz Posted 30-Nov-2004 02:27 GMT Toolset C51 |  Dayligh saving time Code Zal Nawaz Hi, Any one out there have C example code on daylight saving time.? I already have r/w date_Time(), two date_compare() routines based on dallas DS1302. Thanks. | | Read-Only Author Drew Davis Posted 30-Nov-2004 03:41 GMT Toolset C51 |  RE: Dayligh saving time Code Drew Davis Considering all the exceptions to the rules just in the US, I'm not sure you could fit it into an 8051. (Do you really need to account for the fact that Starke County, Kentucky, was in Central Time until 1991, when it became Eastern? Which part of Indiana are you in?)
There's always http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdtime/
That's probably overkill.
If you want the simple rule for the US, DST begins at 2 am on the first Sunday in April and ends at 2 am on the last Sunday in October. Figuring out the first/last Sunday should be straightforward if you calculate the day number for day 1 and then do some mod arithmetic. | | Read-Only Author Andrew Neil Posted 30-Nov-2004 09:17 GMT Toolset C51 |  RE: Dayligh saving time Code Andrew Neil Would it be simpler to include a radio time code receiver? | | Read-Only Author Zal Nawaz Posted 30-Nov-2004 17:10 GMT Toolset C51 |  RE: Daylight saving time Code Zal Nawaz All I need some code to do that arithmetic. Time is already set & running in the machine according to its loaction/state. A piece of code s/b able to set clock one hour back/ahead according to October/April's sundays. | | Read-Only Author Stefan Duncanson Posted 30-Nov-2004 10:13 GMT Toolset C51 |  RE: Dayligh saving time Code Stefan Duncanson Search the internet for the source to the 'C' library function mktime(). | | Read-Only Author Drew Davis Posted 30-Nov-2004 17:32 GMT Toolset C51 |  RE: Dayligh saving time Code Drew Davis The magic Google phrase for calculating the day of the week is "Zeller's Congruence".
http://www.lysator.liu.se/faq/c-faq/c-17.html#17-28
dayofweek(y, m, d) /* 0 = Sunday */
int y, m, d; /* 1 <= m <= 12, y > 1752 or so */
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
| | Read-Only Author Zal Nawaz Posted 30-Nov-2004 17:46 GMT Toolset C51 |  RE: Dayligh saving time Code Zal Nawaz Thanks Drew for the code. | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|