Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calendar
#1
what is the Calendar forumla? i need to figure out when the 2006 callender is repeted. i dont know where to start
Reply
#2
1. Know how many days are in each month
2. know that every month starts the day after the previous
3. know what day january starts on, and the rest fall in place...
[Image: 1403.png]
^ Infrosoft
http://www.thecodeyouneed.us.to/ - A wiki of source code, mostly in PHP and FreeBASIC
http://www.osadvocacy.uk.to/ - Your opinion matters no matter your OS
Reply
#3
Quote:what is the Calendar forumla? i need to figure out when the 2006 callender is repeted. i dont know where to start
When you say "when 2006 calendar is repeated", I assume you mean the next year after 2006 which starts on the same day as 2006 (Sunday), and of course is not a leap year --- like 2012 which starts on a Sunday but is a leap year.

I don't know of any "formula" that will give you this. Proper programming of dates is a lot of work and involves a lot of testing.

I have a date program that I've been using for years. I ran it a few times to find the year when 2006 is repeated, which is 2017.

If you'd like the executablee of my date program, post or PM me your email address.
*****
Reply
#4
Perhaps this could be helpful:

http://en.wikipedia.org/wiki/Calculating...f_the_week
Reply
#5
This calendar I coded recently has all functions you require.
Hope it helps
Code:
'calendar by Antoni Gual 2005
'runs in Qbasic and in FreeBASIC
DEFINT A-Z
DECLARE FUNCTION DayofWeek (y, m, D)
DECLARE FUNCTION daysinmonth (y, m)
DECLARE SUB printmonth (m, y, r, c)
DECLARE SUB printyear (y)
'option byval
'option explicit

DATA "January","February","March","April","May","June","July"
DATA "August","September","October","November","December"
'
'----------------------------------------------------------------------------
DIM y
WIDTH , 50
INPUT "year "; y
CLS
printyear y
SLEEP
end
'
'-------------------------------------------------------------------------
FUNCTION DayofWeek (y, m, D)
'calculates the day of weeek using Zeller's congruences
'returns 0 for monday .... 6 for sunday  
  DIM P, Q
  IF m > 2 THEN
    P = m - 3
    Q = y
  ELSE
    P = m + 9
    Q = y - 1
  END IF
DayofWeek = (D + 1 + Q + Q \ 4 - Q \ 100 + Q \ 400 + CINT(2.6 * P)) MOD 7
END FUNCTION

'
'-------------------------------------------------------------------------
FUNCTION daysinmonth (y, m)
'get nr of days in a month  of a year(check for leap year if february)
SELECT CASE m
CASE 2:  daysinmonth = 28 - ((y MOD 4 = 0) - (y MOD 100 = 0) + (y MOD 400 = 0))
CASE 1, 3, 5, 7, 8, 10, 12: daysinmonth = 31
CASE ELSE:  daysinmonth = 30
END SELECT
END FUNCTION
'
'--------------------------------------------------------------------------
SUB printmonth (m, y, r, c)
DIM i, j, sd, ld, a$, r$
sd = DayofWeek(y, m, 1)
ld = daysinmonth(y, m)
j = 0
LOCATE r, c + 1
READ r$
PRINT r$
LOCATE , c
PRINT " Mo Tu We Th Fr Sa Su"
LOCATE , c
DO
FOR i = 0 TO 6
   IF i = sd OR j > 0 THEN j = j + 1
   IF j < 1 THEN PRINT "   ";  ELSE PRINT USING " ##"; j;
   IF j = ld THEN EXIT SUB
NEXT
PRINT : LOCATE , c
LOOP
END SUB
'
'---------------------------------------------------------------------------
SUB printyear (y)
DIM m, i, j
m = 1
locate,,0
print
PRINT "   Calendar of "; y;
FOR i = 0 TO 3
FOR j = 0 TO 2
  printmonth m, y, i * 9 + 4, j * 25 + 4
  m = m + 1
NEXT
NEXT
locate 40,1,1
END SUB
Antoni
Reply
#6
Quote:This calendar I coded recently has all functions you require.
Hope it helps
Congratulations, Antoni.
A truly beautiful and precise date program. Big Grin
*****
Reply
#7
And about the reuse of the calendar, the calendar FAQ says:
Quote:Let us first assume that you are only interested in which dates fall on which days of the week; you are not interested in the dates for Easter and other irregular holidays.

Let us further confine ourselves to the years 1901-2099.

With these restrictions, the answer is as follows:

* If year X is a leap year, you can reuse its calendar in year X+28.
* If year X is the first year after a leap year, you can reuse its calendar in years X+6, X+17, and X+28.
* If year X is the second year after a leap year, you can reuse its calendar in years X+11, X+17, and X+28.
* If year X is the third year after a leap year, you can reuse its calendar in years X+11, X+22, and X+28.

Note that the expression X+28 occurs in all four items above. So you can always reuse your calendar every 28 years.

But if you also want your calendar's indication of Easter and other Christian holidays to be correct, the rules are far too complex to be put to a simple formula. Sometimes calendars can be reused after just six years. For example, the calendars for the years 1981 and 1987 are identical, even when it comes to the date for Easter. But sometimes a very long time can pass before a calendar can be reused; if you happen to have a calendar from 1940, you won't be able to reuse it until the year 5280!
Antoni
Reply
#8
Quote:And about the reuse of the calendar, the calendar FAQ says......
The calendar FAQ makes for interesting reading. However, I tested the 2 algorithms in sections 2.13.7 and .8 that it has for the calculation of Easter, and they do not work at all. Since it does not specify, I tried the algorithms using integer, long, and single variable types but could not get the right answers. In some cases Easter was only one day off. In others, the month was correct but the day was a negative number.

I hope no one adopts these algorithms into their programs. If you really want a bullet-proof Easter algorithm, see Donald Knuth's book on Fundamental Algorithms. Set all the variables to long, and replace the TEMP MOD 30 with TEMP-30*INT(TEMP/30) because TEMP can be negative and the MOD won't work in Basic.
EDIT: Actually there is no TEMP variable in the original. I had to place the expression being "mod'ed" into TEMP to do the above.

The calendar FAQ code also uses a MOD 30, but I didn't want to mess around with their code.

Maybe the authors of the calendar FAQ did what Knuth once said as a joke:
"Beware of bugs in the above code;
I have only proved it correct, not tried it."
*****
Reply
#9
Good to know it...I have never used a formula from that FAQ Big Grin
For easter i use a snippet i found at the ABC packets, it seems to give good results:
Code:
DEFINT A-Z
SUB EaSun (Year, Month, Day) ' Finds month and day of Easter Sunday
   J = Year MOD 19
  K = Year \ 100
  L = Year MOD 100
  M = K \ 4
  N = K MOD 4
  O = L \ 4
  P = L MOD 4
  Q = (8 * K + 13) \ 25
  R = (19 * J + K - M - Q + 15) MOD 30
  S = (J + 11 * R) \ 319
  T = (2 * (N + O) - P - R + S + 32) MOD 7
  U = R - S + T
  
  Month = (U + 90) \ 25
  Day = (U + Month + 19) MOD 32
END SUB
Antoni
Reply
#10
Quote:Good to know it...I have never used a formula from that FAQ Big Grin
For easter i use a snippet i found at the ABC packets, it seems to give good results:
Code:
DEFINT A-Z
SUB EaSun (Year, Month, Day) ' Finds month and day of Easter Sunday
   J = Year MOD 19
  K = Year \ 100
  L = Year MOD 100
  M = K \ 4
  N = K MOD 4
  O = L \ 4
  P = L MOD 4
  Q = (8 * K + 13) \ 25
  R = (19 * J + K - M - Q + 15) MOD 30
  S = (J + 11 * R) \ 319
  T = (2 * (N + O) - P - R + S + 32) MOD 7
  U = R - S + T
  
  Month = (U + 90) \ 25
  Day = (U + Month + 19) MOD 32
END SUB

that is insane.

reminds me of agamemnus' code ;P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)