Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

day of week
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

day of week

by mtbf0 on Wed Sep 02, 2009 11:05 am

i don't have this clock, but if anybody wants to add a day of week display, here's a bit of code adapted from Calendrical Calculations by Nachum Dershowitz, Edward M Reingold.

Code: Select all | TOGGLE FULL SIZE
uint8_t dayOfWeek (uint8_t month, uint8_t date, uint8_t year) {
  unsigned int m, d, y;
  d = (unsigned int) date;
  m = (unsigned int) month;
  y = (unsigned it)year + 2000;
  if ((14 - m) / 12) {
    y--;
    m += 10;
  }
  else m -= 2;
  return (unsigned char) (( d + y + y / 4 - y / 100 +
          y / 400 + (31 * m) / 12) % 7);
}


returns values 0, (sunday), through 6, (saturday).
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: day of week

by adafruit on Wed Sep 02, 2009 4:34 pm

there's a dotw calculator in the clock. it should work ok and takes into account leapyears :)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: day of week

by mtbf0 on Wed Sep 02, 2009 7:33 pm

ladyada wrote:there's a dotw calculator in the clock. it should work ok and takes into account leapyears :)


oops. sorry. missed that.

can i offer you some code to automatically adjust for daylight savings time? of course, every time congress changes the start and end dates it'll break the clock.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: day of week

by richms on Wed Sep 02, 2009 11:10 pm

"Congress" implies US centric design which IMO is not ideal for code that is to be used world wide.

One thing tho, if you do allow for programmable daylight savings dates, is that southern hemisphere rolls over with daylight savings active, so the start date is after the end date. Lots of stuff freaks out at that concept insisting that the start date is before the end date.

richms
 
Posts: 558
Joined: Tue Jan 20, 2009 3:05 am
Location: New Zealand

Re: day of week

by mtbf0 on Thu Sep 03, 2009 8:36 am

sorry. should have said every time congress diddles the dates it breaks my clock. the only real dumbass coding assumptions i made are that dst happens at all and that the time changes at 2:00 a.m.

but, yes, my clock is u.s. centric. main reason i built it after all was to wake me up for my government job. it doesn't go off on u.s. federal holidays, but would work perfectly well if you dropped the whole country into the southern hemisphere. won't work in arizona, though, unless you're on the navajo reservation.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: day of week

by adafruit on Thu Sep 03, 2009 3:41 pm

ya i didnt include daylight savings, its not really possible to support it and sell it worldwide :D

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: day of week

by caitsith2 on Thu Sep 03, 2009 6:25 pm

Actually, that is what I like about this clock design. Want a feature, like day of week alarm, or daylight savings time, easy to program in.

Daylight saving time changes, then just rewrite the firmware to handle the changes.

I have an alarm clock, which if I was able to, I would change its daylight saving time, or turn it off outright, due to the fact, that its obsoleteness has made me late for work before.

caitsith2
 
Posts: 217
Joined: Thu Jan 18, 2007 11:21 pm

Re: day of week

by madworm_de on Thu Sep 03, 2009 8:26 pm

Who needs daylight saving anyway ?

If I had 3 wishes, getting rid of that nonsense would be one of them. If there is the faintest chance that more people suffer from it as I do, I hope they're not bus drivers or similar. I wouldn't want to get killed by driving zombies.

The fact that daylight saving does anything good is a myth, just like "spinach contains iron and is good for children".
NO LARDO CHIPS
madworm_de
 
Posts: 99
Joined: Mon Jun 09, 2008 6:56 am

Re: day of week

by caitsith2 on Fri Sep 04, 2009 2:39 am

The only thing Daylights saving time is, is bureaucratic BS. I would love if we could live without it. In the mean time, till that day comes, well, at least I will be able to reprogram the clock at the firmware level to work around the bureaucratic bs as it happens, instead of having an obsolete clock as I have now.

caitsith2
 
Posts: 217
Joined: Thu Jan 18, 2007 11:21 pm

Please be positive and constructive with your questions and comments.


cron