Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

It's Summer, But Do You Know What Day of the Week It Is?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • It's Summer, But Do You Know What Day of the Week It Is?

    ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
    This is a discussion about It's Summer, But Do You Know What Day of the Week It Is?.

    Click here for the article.


  • #2
    It's Summer, But Do You Know What Day of the Week It Is?

    ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
    It's a nice clean piece of logic to do the calculation. But at the end of the program, you've done something I often see. Your comparison 'nDayOfWeek > 5' is reallty testing for 'nDayOfWeek = 6' is it not? Why not code for the specific? When I see logic like this I always stop and think (of course, maybe that's the point ;-) ), "What's this comparison looking for?" Would it make it quicker for another developer looking at it later if it was just coded 'nDayOfWeek = 6'? Or am I overlooking something?

    Comment


    • #3
      It's Summer, But Do You Know What Day of the Week It Is?

      ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **

      Code

      Comment


      • #4
        It's Summer, But Do You Know What Day of the Week It Is?

        ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
        Hi Bob, It seems that a comment is off :>) ** (e.g., 0=Mon, 1=Tues, 3=Wed, etc. 7=Sun). Shouldn't that be 6=Sun. Dave Boettcher

        Comment


        • #5
          It's Summer, But Do You Know What Day of the Week It Is?

          ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
          Yes, the comment is "off" and Sunday is returned as 6 until converted. Thanks!

          Comment


          • #6
            It's Summer, But Do You Know What Day of the Week It Is?

            ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
            In the early 80's I had a book on Basic games. Not VB, Basic. It had Zeller's Congruence in it. I learned enough Basic to re-write it in RPG II (remember that?). I even keyed the Basic source code in as comments. I thought I was one of three or four programmers alive who knew about Zeller's Congruence. That little routine amazed many people over the years. Nice to see an old friend has a new lease on life.

            Comment


            • #7
              It's Summer, But Do You Know What Day of the Week It Is?

              ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
              Hi Bob! Interesting that they'd name an algorithm after a Canadian discount department store chain! ;-) You can probably speed up your procedure a little bit. Instead of using subexpressions like "%int(nYear/4)", code "%div(nYear:4)" instead. The former does a packed decimal division, with conversion to integer. The latter does the division in integer format. (BTW, my summer project is redecorating a couple of rooms in my basement.) Cheers! Hans

              Comment


              • #8
                It's Summer, But Do You Know What Day of the Week It Is?

                ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                So %int(x/y) is less efficient than %div(x:y) That's good, Thanks Hans. I've changed the code in my RPG xTools version to reflect this subtlety. Too bad %int(x/y) is more readable to me.

                Comment


                • #9
                  It's Summer, But Do You Know What Day of the Week It Is?

                  ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                  Based on comments from Hans and other readers, I've updated the code and fixed the comments for Zeller's conguence. This is only an excerpt as reposted the entire procedure would be pointless.
                  Code

                  Comment


                  • #10
                    It's Summer, But Do You Know What Day of the Week It Is?

                    ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                    Divide 7 into the number of days from a known Sunday. The remainder will be the day of week with 0=Sunday and 6 = Saturday. Add 1 to the remainder to make a return value of 1 - 7. Using 0001-01-01 will ensure any date can be handled correctly. Because 0001-01-01 is a Monday Add 1 to the number of days to correct.
                    Code

                    Comment


                    • #11
                      It's Summer, But Do You Know What Day of the Week It Is?

                      ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                      I believe that the point of the article was to examine an RPG solution that would work with Zeller's Congruence. but. . . . . As long as other methods are being posted. . . .I use this one. Dave
                      Code

                      Comment


                      • #12
                        It's Summer, But Do You Know What Day of the Week It Is?

                        ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                        "Zeller's congruence isn't a game; it's a very efficient way to calculate the day of the week, given any date. While the OS/400 CEEDYWK API will do this for you, sometimes it's fun to play with RPG."

                        Comment


                        • #13
                          It's Summer, But Do You Know What Day of the Week It Is?

                          ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                          (This was supposed to be a reply to "Different method, same result" by MauriceT. Sorry...) I use this technique, too. To get Sunday = 1, I code it a little differently - if 0001-01-01 is Monday, that would make 0001-01-07 a Sunday, right? DayOfWeek = %rem(%diff(Date:d'0001-01-07':*d):7) + 1 will return 1 for Sunday thru 6 for Saturday. Now, here's my question on this technique (just to shoot the breeze): Does it work on dates prior to the Gregorian Calendar? Does it matter...?

                          Comment


                          • #14
                            It's Summer, But Do You Know What Day of the Week It Is?

                            ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                            This method works as long as the calculation of the number of days between dates is correct. Calculating dates using different calendars would cause problems. My research shows that there was an eleven day difference between the Julian calendar and the Gregorian calendar at the time of the switch. September 1, 1752 was on Tuesday according to the Julian calendar, but was on a Friday according to the Gregorian calendar.

                            Comment


                            • #15
                              It's Summer, But Do You Know What Day of the Week It Is?

                              ** This thread discusses the article: It's Summer, But Do You Know What Day of the Week It Is? **
                              There are lots of methods available to compute day of week. Here's one more: Use functions in the C run-time library. First, call "timer=time(0);" to get the current time. It returns a number representing seconds since the beginning of the Unix epoch, which started on January 1, 1970. Next, convert that to a "tm" structure using function "tmptr=localtime(&timer);". Field "tm_wday" in the tm structure represents day of week, with 0=Sunday. You can go one step further and use "asctime()" or "strftime()" to format a tm structure into a character string. For example, "strftime(str,strlen,"%A",tmptr)" will return the day of the week as a character string. This technique has the advantage of being locale sensitive. That is, you don't have to change your code if you want your app to run in different countries. Look up strftime to see how flexible it can be in the formatting of date/time strings. This of course begs the question: Which technique is best? The answer for any one situation may depend on various factors. As I mentioned, you may need to consider locale if your app is to be used in multiple countries. Regarding performance, I would guess that computing day of the week would not be a performance bottleneck in any application. For example, in many cases, it may be something you only have to compute once per day. Cheers! Hans

                              Comment

                              Working...
                              X