157. Calendar functions ~~~~~~~~~~~~~~~~~~ The first of these, FNnumdays at line 1040, is derived from a short Function I saw on Micronet, credited to Frank McAree. It returns the number of days in month m% in year y%; eg PRINT FNnumdays(7,1987) would print the number of days in July 1987. It takes account of all Leap Years, which the original didn't. Years divisible by 4 are Leap years, except for those divisible by 100 but not by 400. Eg the year 1900 wasn't a Leap year, but 2000 will be. The present Gregorian calendar system dates from 1752 in most countries; before that it was chaos! The second, FNday at line 1070, is one refined from an Acorn User program by Robin Newman. It returns the day of the week on the date d%,m%,y%; eg PRINT FNday(22,3,1986) would print the day of the week on 22nd March 1986 as a string, "Sat". If however, you want the day as a complete word string, eg "Saturday" rather than "Sat", then put the full words in line 1050, padded with trailing spaces to 9 characters each, ie "Saturday-Sunday---Monday---Tuesday--WednesdayThursday-Friday---", ("-" represents a space), and alter both the figures "3" to "9". If you would rather it returned the day of the week as a number, then alter line 1050 to =day% . This gives 0 for Saturday, 1 for Sunday and so forth, so if you would prefer 7 for Saturday instead of 0, then alter line 1050 to =day%-(day%MOD7=0)*7 . (This is more elegant and structured than using IFday%=0THEN=7 ELSE=day% .) These two Functions can be used quite independently, but the Procedure PROCcalendar at line 1000 shows just one way in which they might be used together. It displays a crude calendar for month m% in year y%, eg PROCcalendar(7,1987) for July 1987. 1000 DEFPROCcalendar(m%,y%):LOCALd% 1010 FORd%=1TOFNnumdays(m%,y%):PRINTFNday(d%,m%,y%)" ";d%:NEXT 1020 ENDPROC 1030 : 1040 DEFFNnumdays(m%,y%) 1050 =30+ABS((m%>7)+(m%MOD2))+(m%=2)* (2+(((y%MOD4)=0AND(y%MOD100)>0)OR((y%MOD400)=0))) 1060 : 1070 DEFFNday(d%,m%,y%):LOCALday% 1080 IFm%<3THENm%=m%+12:y%=y%-1 1090 day%=d%+2*m%+INT(0.61*(m%+1))+y%+y%DIV4-y%DIV100+y%DIV400+2 1100 day%=day%MOD7 1110 =MID$("SatSunMonTueWedThuFri",day%*3+1,3)