Shop OBEX P1 Docs P2 Docs Learn Events
Day of the Week.....Ahhh GAIN!!! — Parallax Forums

Day of the Week.....Ahhh GAIN!!!

hmlittle59hmlittle59 Posts: 404
edited 2010-01-08 23:42 in General Discussion
OK, yes I've ask this before but got a routine that I could not get to work...If someone wants a challenge then fix this routine or tell me it works great like it suppose to, and then dummy it down for me....if it can be any more........thanks


 IF month < 3 THEN
  month =  month + 12
  year =  year - 1
 ENDIF
 Day = (Date+2*month+(3*(month +1)/5)+year+(year/4)-(year/100)+(year/400) + 1) // 7





I want to learn how to do this...

thanks again

PS:I have one more I want to get and get working.....(Day Light Savings Time)...Yea Haa.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

hmlittle59

Comments

  • ercoerco Posts: 20,260
    edited 2009-12-30 22:34
    You should post·the math formulas you're trying to implement in PBasic. Are you sure they work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-12-31 00:20
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-31 05:06
    The Code is listed, I could not get it to work.....I will try PJ Allen's code

    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • ZootZoot Posts: 2,227
    edited 2009-12-31 05:26
    PJ, shouldn't this:

    LOOKUP total, [noparse][[/noparse]"Mo","Tu","We","Th","Fr","Sa","Su"], dayofwk
    
    DEBUG "Given: ", month, dayofmon, year, CR
    DEBUG "The day of the week is: ", total, CR
    
    



    Be this (or something like it):

    LOOKUP total, [noparse][[/noparse]"M","t","W","T","F","s","S"], dayofwk ' it's a byte
    
    DEBUG "Given: ", month, dayofmon, year, CR
    DEBUG "The day of the week is: ", dayofwk, CR
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-31 05:38
    Tried the code and I could not get it to work as is...I added some "DEC2" to get the variables to display but it still did not display the Dayofwk.


    any help

    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2009-12-31 19:42
    Attached is another program for you to try. The core is an ordinal date, a number that increases from 1 on Monday, January 1st, 2001, to 3287 on today, Thursday Dec. 31, 2009, and will be 36159 on Thursday, Dec. 31st, 2099. That number, modulo 7, is the day of the week, with Monday being number 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-31 22:49
    Tried the Code Tracy and it works....Thanks a lot. Next I will Break down the Code so I can better understand how it works. My next challenge is Code that will let me detect Day Light Saving Time? I noticed that this year my DS1302 did not change and I was wandering how to detect the 1st, 2nd, 3rd, 4th weekend of any month(May & Oct). I have figured out how to loop it in my routines, since there is no interrupts in BS2 PBASIC.


    thanks again

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-01-01 00:00
    This works better, now.· There were a few traps, oh well, thought they were pretty obvious.·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-01-01 00:14
    Now, with DEBUGINs...
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-01-01 08:32
    Provided you are only interested in years 1901-2099, you can ignore the 100's test for leap year (i.e. /4 only will yield correct answer as 2000 is a leap year but 1900 & 2100 were/are not).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-01-01 18:58
    hmlittle59, Note that there is a link at the top of the code I posted to an breakdown of how it works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-01 22:46
    Thanks Tracy....Did a six page printout

    Pj Allen I have been trying your code and Sunday does not want to print out to the screen(Monday Prints). February 7,21,2010 makes the program restart...

    I'm using the BS2e...If that helps

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-01-01 23:10
    hmlittle59,

    It's a little snag with the LOOKUP and total.· I got that turned around.

    Exactly how are you participating in the process, is it strictly as a consumer?
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-01 23:16
    To All,

    Looking at when Day Light Saving Time starts/Ends, I might be able to work up a routine that will detect the 2nd Second weekend of the Month using(GOSUB) to some of your code for Day Of The Week. I will have to save any flags in the DS1302 RAM/EEPROM RAM, no space left. My Pseudo Code looks like it will work.


    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-01-02 06:43
    A similar problem. In my neighborhood we have street sweeping on the third Monday of every month, with a hefty fine if cars are parked by the curb. Okay, if the first day of the month happens to be a Monday, day of week 1 in our scheme, then add 14 to peg the street sweeping day. If the first of the month is a different day, add a larger value, according to,
    day add
    1 Mon +14
    0 Sun +15
    6 Sat +16
    5 Fri +17
    4 Thu +18
    3 Wed +19
    2 Tue +20

    And to calculate on a Stamp...
    month = 1 : year = 10  ' for example
    GOSUB day_of_week   ' returns dow=5, for Friday Jan 1, 2010
    [s]sweeping =  8 - dow  // 7 + 14  ' result is 3 + 14, math does the above number mapping[/s]
    sweeping =  8 - dow  // 7 + 15  ' result is 3 + 15, corrected, the extra +1 being for day 1 of the month
    DEBUG DEC sweeping   ' result for Jan 2010 is Monday the 18th.,  date to move car or incur fine
    



    For a more general formula, for some event that will happen on the nDay'th wDay of the month, e.g. 3rd Monday
    wDay =  1  ' sweeping on Monday, day 1 of a week
    nDay  = 3  ' being the third Monday of the month 1st, 2nd, 3rd, 4th
    [s]sweeping =  (wDay+7) - dow  // 7 + ((nDay - 1) * 7)  ' mark calendar for this date[/s]
    sweeping =  (wDay+7 - dow)  // 7 + ((nDay - 1) * 7) + 1  ' mark calendar for this date
     ' correction, adding to day=1
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 1/2/2010 6:50:25 PM GMT
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-02 16:52
    To All,

    Did the rest of the Pseudo Code for Day Light Savings Time and it looks like it will work...we'll see..
    Google says DLST is 3rd wk of March and 1st wk of Nov. My logic is to find the 1st day of March, get its DAY, then if its not SUNDAY then ADD 8, after that start counting up while GOSUBing to Day Of Week check til I reach the next SUNDAY. That should be the 2nd SUNDAY of the Month......LET me know if this makes ANY since.....My brain says yes!!!

    .Wife says Christmas decoration must come down now!!!...Got to go

    thanks alle

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-01-02 18:43
    For the second Sunday of March, I think that if you start at the 8th day of the month, and move forward one day at a time, the first Sunday you find will be the second one of the Month.

    In the calculated version, if you know the day of week (=dow) on the first day of the month, then
    springForward2Savings = 7 - dow // 7 +8
    So March 1st, 2010 is a Monday, dow=1, so springForward2Savings is the 14th. (7 - 1 // 7 + 8 = 6//7 + 8 = 6 +8 = 14)
    (I made a off-by-one correction to the formula in my previous post)

    The observance of summer time and the specific dates is highly varied around the world.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-02 21:00
    Hello All,

    While taking down Christmas Decorations, I realize that on my last post I stated that I would just ADD 8 to the 1st of the month if it did not equal SUNDAY but that would be one(1) day to much...it should be 7. That way it would only take it out 1 week and not skip a day with 8.

    OOPs!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-02 21:36
    Hello Tracy,

    Just came in and started typing before I noticed your POST. Your correct, that logic should work even better...I don't always see these simple things...Glad I posted the thought.

    Thanks again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-06 03:48
    Hello Tracy,
    This is the second attempt, I tried to reply earlier and got a server error...So this is 2 bummed out hours later...

    Any way, I tried to implement your code and the Calender Dates does not always come out correct. I'm using part of the Parallax DS1302 Demo code with my own. I use Button Command with switches to change the time up/down and it works OK. I go from BCD format(DS1302) to DEC format(Serial LCD Parallax) to make changes to the time on the screen. Then I convert it back to BCD to save in the DS1302. All this works find. Now taking the (mm/dd/yy) variables and running them through your code, I'm not always getting the correct DOW. Also SATURDAY does not spell out(=?S), I'm using WORD/NIB variable and I've tried going through the BCD to BIN routine, but to no avail. I only want to get the value (1 - 7) and use it in the Demo routine that I'm already using to get the DOW. Again the two formats that I'm using is BCD & DEC.


    Let me know if you have any thoughts on what I'm missing.

    PS: Hope I don't get a server error this time...here goes

    Howard

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-01-06 06:01
    Can you have it debug the decimal values, along with the computed value dow?
    DEBUG CR, DEC2 mm, DEC2 dd, DEC2 yy, TAB, DEC JD, TAB, DEC dow
    Right after dow is computed. I threw JD in there too, assuming that is still part of the computation. My guess is that there is some variable conflict somewhere. But I'd be better equipped to comment if I could see values that actually fail. Also, it might help if you attach your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-07 18:01
    Hello Tracy,

    24hr bug got me...I will try and focus if I can to get the values so this can be figured out...Thanks


    Howard

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-01-08 22:54
    Hello Tracy,

    Think I got it working, put in a lot of Date(s) and they all seem to come out correct. The conversion from DS1302(BCD) to Parallax LCD Screen(DEC) value is what I needed to work with(insert) into your routine to get it working. The scrambled day(SATURDAY) came from the two(2) different DOW lookup tables starting point. Yours is from zero(0) and the DEMO program is from one(1). I looked at the table twice but didn't think it would affect the calculation. After you said to print out the values, I did and that's when I realized what was happening. Thanks...Now it's on to trying to get the "DAY LIGHT SAVING" routine to work.

    day  = date//7                         ' day of week is julian date modulo 7
    
    day  = date//7 + 1                     ' day of week is julian date modulo 7 +1 for Parallax DEMO DOW Look up
    
    



    Thanks Again...I'll Post it when done or the next bump in the road.

    Howard

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-01-08 23:42
    Good deal!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.