Micro Julius (Julian Calendar)
- Type
- Utility
- Category
- Perpetual calendar and date calculator
- Author
- Charles Postle
- Published in
- Antic, June 1986 (Vol. 5, No. 2)
- Year
- 1986
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, Atari BASIC
- Tags
- antic, calendar, dates, julian-day-number, utility, math, graphics-0, charles-postle, 1986
About the program
"Did you ever want to know how many days old you are?" Charles Postle, a construction superintendent from the Las Vegas area who wrote much of his own software in BASIC, called his perpetual calendar Micro Julius. Enter a date and you can find the number of days to another date, count forwards or backwards by a number of days, or draw the whole month as a calendar page. The article's examples: someone born on 5 October 1959 was 9,719 days old on 15 May 1986, and a 90-day diet started that day would end on Wednesday, 13 August.
The program works for dates between 1 March 1900 and 28 February 2100. The editors joked that readers should look for an update in the February 2100 issue.
Typing it in
Most special characters are line-graphics and inverse characters in the strings that draw the calendar grid (20 lines in all). {inv}…{/inv} means press the Atari key before and after, and {CTRL-R}, {CTRL-S}, {CTRL-Q} and so on mean hold CTRL and press the letter. They draw the lines, crossings and corners of the grid ({CTRL-R} alone appears 88 times). {CLEAR} is ESC then SHIFT-CLEAR, and {UP} is ESC then CTRL-−. The program uses ERX as a variable name, which Atari BASIC allows but some later BASICs reserve. The magazine printed TYPO II codes.
How to use it
Enter a date as month, day, year with commas: 5,15,1986 and RETURN. The program prints it in full with the day of the week. Then choose from the menu:
- Enter a second date and get the number of days between them.
- Subtract a number of days.
- Add a number of days.
- Start again with a new date.
- Quit.
- Draw the calendar page for the month, with the day highlighted.
Postle warned against using it for loan calculations, because banks often use 30-day months and a 360-day year.
How it works
- Julian day numbers. Arithmetic on dates is easy if each date is first turned into a running day count. Lines 120–170 do this with the classic formula
INT(365.25*YY)+INT(30.6001*M)+D. January and February are treated as months 13 and 14 of the previous year (lines 130–150), so the leap day falls at the end of the counting year and needs no special case. - Back to a date. Lines 180–270 reverse the calculation. Lines 290–310 find the weekday from the day number with a remainder after dividing by 7. The tiny
1E-03added in line 310 guards against rounding errors. - The calendar page (lines 800–1420) finds the weekday of the 1st, takes the day number of the 1st of the following month to get the month's length, and fills a string
C$with the grid and the dates. The chosen day is made inverse.
Changes from the published listing
One change, so the program also runs under Altirra BASIC, the free replacement BASIC built into many emulators. Altirra BASIC adds a function called ERR, so it rejected the published lines that use that word as the start of a variable name. The variable is renamed everywhere in the program. The new name is the same length, so the memory layout is unchanged and the program behaves exactly as published on genuine Atari BASIC. If you type it in from the magazine, the original names work fine on a real Atari.
| Published | Now | Lines |
|---|---|---|
ERR |
ERX |
80, 84, 610, 625, 1740, 1760, 1770, 1780, 1790 |
Listing
10 REM JULIAN CALENDAR
12 REM BY CHARLES POSTLE
14 REM (c) 1986, ANTIC PUBLISHING
20 DIM A$(62),C$(75)
30 DIM M$(9),DAY$(9),I$(2)
40 DIM T$(2),D$(2),B$(2)
50 GRAPHICS 0:POKE 82,2
60 ? "This program calculates a number of":? "answers relating to days and dates"
70 ? "between March 1, 1900 and February":? "28, 2100 using the Julian Day Method.":?
80 SKIP=1:ERX=1:TRAP 84:? "ENTER DATE #1 (M,D,Y)":? :INPUT M,D,Y
82 GOSUB 1740
84 IF ERX=1 THEN ? "{UP}{UP}{UP}";:GOTO 80
90 TRAP 40000:? :GOSUB 120
95 JSAFE=JDN:SAFEDOW=DOW:SAFEM=M:SAFEY=Y:SAFED=D
100 JDN1=JDN
110 GOTO 180
120 REM CALCULATE JULIAN DAY NUMBER
130 IF M=1 THEN YY=(Y-1):M=(M+13):GOTO 160
140 IF M=2 THEN YY=(Y-1):M=(M+13):GOTO 160
150 IF M>2 THEN M=M+1:YY=Y
160 JDN=INT(365.25*YY)+INT(30.6001*M)+D
170 RETURN
180 REM CONVERTS JULIAN DAY NUMBER TO DATE
190 YY=INT((JDN-122.1)/365.25)
200 M=INT((JDN-INT(365.25*YY))/30.6001)
210 D=JDN-INT(365.25*YY)-INT(30.6001*M)
220 IF M=14 THEN M=M-13:GOTO 250
230 IF M=15 THEN M=M-13:GOTO 250
240 IF M<14 THEN M=M-1:GOTO 250
250 IF M>2 THEN Y=YY
260 IF M=1 THEN Y=YY+1:GOTO 280
270 IF M=2 THEN Y=YY+1
280 GOSUB 1490
290 REM CALCULATE DAY OF THE WEEK.
300 DOW=(7*(((JDN+5)/7)-INT((JDN+5)/7)))
310 DOW=1+INT(DOW+1E-03)
320 GOSUB 1630
330 IF G=2 THEN RETURN
340 REM PRINT M,D,Y & DOW
350 ? M$;" ";D;", ";Y;" ";DAY$
360 IF G=1 THEN 680
370 GOSUB 1800
380 FOR F=11 TO 22
390 POSITION 2,F:GOSUB 1720
400 NEXT F
410 REM MENU
420 POSITION 2,10
430 ? :? "CHOOSE A CALCULATION:":?
440 ? "{inv}1{/inv} ENTER A NEW DATE TO FIND THE DIFFERENCE IN DAYS?"
450 ? "{inv}2{/inv} SUBTRACT A NUMBER OF DAYS FROM THE ABOVE DATE?"
460 ? "{inv}3{/inv} ADD A NUMBER OF DAYS TO THE DATE ABOVE?"
470 ? "{inv}4{/inv} CHOOSE A NEW DATE?"
480 ? "{inv}5{/inv} END PROGRAM?"
490 ? "{inv}6{/inv} DRAW CALENDAR?"
500 ? "CHOICE>>";:CLOSE #1:OPEN #1,4,0,"K:"
510 GET #1,CH:SKIP=0
520 IF CH<49 OR CH>54 THEN 510
530 CLOSE #1:CH=CH-48:? CH
540 FOR F=10 TO 21
550 POSITION 2,F
560 GOSUB 1720
570 NEXT F
580 POSITION 2,11
590 REM BRANCH TO CHOICE.
600 ON CH GOTO 610,720,750,780,790,800:REM BRANCH ON CH
610 ERX=1:TRAP 625:? "ENTER DATE #2 (M,D,Y)":? :INPUT M,D,Y
620 GOSUB 1740
625 IF ERX=1 THEN ? "{UP}{UP}{UP}";:GOTO 610
630 TRAP 40000:GOSUB 120
640 JDN2=JDN
650 JDND=ABS(JDN1-JDN2)
660 G=1:POSITION 2,11:GOSUB 1720:GOSUB 1720
670 GOTO 180
680 ? :? "DIFFERENCE=";JDND;" DAYS"
690 GOSUB 1800
700 G=0
710 GOTO 380
720 ? "ENTER NUMBER OF DAYS TO BE SUBTRACTED"
730 INPUT JDN2:JDN=JDN1-JDN2
740 GOTO 180
750 ? "ENTER NUMBER OF DAYS TO BE ADDED"
760 INPUT JDN2:JDN=JDN1+JDN2
770 GOTO 180
780 GOTO 50
790 ? "{CLEAR}":END
800 REM FINDS THE FIRST DAY OF THE MONTH.
805 JDN1=JSAFE:DOW=SAFEDOW:M=SAFEM:Y=SAFEY:D=SAFED
810 W=D:D=1:G=2:GOSUB 120
820 JDN=JDN1:GOSUB 180
830 DIF=DOW*2-1
840 YEAR=Y
850 REM FINDS THE FIRST DAY OF THE NEXT MONTH.
860 M=M+1:IF M=13 THEN M=1:Y=Y+1
870 GOSUB 120
880 REM THE NUMBER OF DAYS ON THE CALENDAR.
890 E=JDN-JDN1
900 REM ASSIGNS DAYS TO A$ MATRIX
910 FOR X=1 TO E
920 IF X<10 THEN B$(1,1)=" ":B$(2,2)=STR$(X):A$(X*2-1,X*2)=B$:GOTO 950
930 A$(X*2-1,X*2)=" "
940 A$(X*2-1,X*2)=STR$(X)
950 NEXT X
960 REM FIGURES THE DAY TO BE HIGHLITED.
970 IF W<10 THEN T$=STR$(W):T=ASC(T$):D$(1,1)="{inv} {/inv}":D$(2,2)=CHR$(T+128):A$(W*2-1,W*2)=D$:GOTO 990
980 T$=STR$(W):T=ASC(T$(1,1)):TT=ASC(T$(2,2)):D$(1,1)=CHR$(T+128):D$(2,2)=CHR$(TT+128):A$(W*2-1,W*2)=D$
990 REM CLEARS THE LAST TWO DAYS OF THE CALENDAR.
1000 IF E=31 THEN GOTO 1040
1010 FOR X=E*2+1 TO 62
1020 A$(X,X)=" "
1030 NEXT X
1040 REM ASSIGNS DAY OF WEEK SYMBOLS TO WEEK ONE.
1050 FOR N=1 TO 7
1060 READ I$:C$(N*2-1,N*2)=I$
1070 NEXT N
1080 GOTO 1100
1090 DATA SU,MO,TU,WE,TH,FR,SA
1100 FOR N=8 TO 37
1110 C$(N*2-1,N*2)=" "
1120 NEXT N
1130 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320 FOR H=22 TO 28
1330 ? C$(H*2-1,H*2);"|";
1340 NEXT H
1350 ? :? "{CTRL-A}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-D}":? "|";
1360 FOR H=29 TO 35
1370 ? C$(H*2-1,H*2);"|";
1380 NEXT H
1390 ? :? "{CTRL-A}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-S}{CTRL-R}{CTRL-R}{CTRL-X}{CTRL-R}{CTRL-R}{CTRL-X}{CTRL-R}{CTRL-R}{CTRL-X}{CTRL-R}{CTRL-R}{CTRL-X}{CTRL-R}{CTRL-R}{CTRL-C}":? "|";
1400 FOR H=36 TO 37
1410 ? C$(H*2-1,H*2);"|";
1420 NEXT H
1430 ? :? "{CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-X}{CTRL-R}{CTRL-R}{CTRL-C}":G=0
1440 ? :? :? " MORE (Y-N)";:OPEN #1,4,0,"K:"
1450 GET #1,YN
1460 IF YN=89 THEN CLOSE #1:POKE 82,2:RUN
1470 IF YN=78 THEN CLOSE #1:POKE 82,2:GRAPHICS 0:END
1480 GOTO 1450
1490 REM CONVERTS NUMBER TO MONTH.
1500 ON M GOTO 1510,1520,1530,1540,1550,1560,1570,1580,1590,1600,1610,1620
1510 M$="JANUARY":RETURN
1520 M$="FEBRUARY":RETURN
1530 M$="MARCH":RETURN
1540 M$="APRIL":RETURN
1550 M$="MAY":RETURN
1560 M$="JUNE":RETURN
1570 M$="JULY":RETURN
1580 M$="AUGUST":RETURN
1590 M$="SEPTEMBER":RETURN
1600 M$="OCTOBER":RETURN
1610 M$="NOVEMBER":RETURN
1620 M$="DECEMBER":RETURN
1630 REM CONVERTS NUMBER TO DAY OF WEEK.
1640 ON DOW GOTO 1650,1660,1670,1680,1690,1700,1710
1650 DAY$="SUNDAY":RETURN
1660 DAY$="MONDAY":RETURN
1670 DAY$="TUESDAY":RETURN
1680 DAY$="WEDNESDAY":RETURN
1690 DAY$="THURSDAY":RETURN
1700 DAY$="FRIDAY":RETURN
1710 DAY$="SATURDAY":RETURN
1720 ? " ":REM 37 SPACES
1730 RETURN
1740 ERX=0:REM VALID DATE?
1750 IF Y<100 THEN Y=Y+1900
1760 IF M<1 OR M>12 OR M<>INT(M) THEN ERX=1
1770 IF Y<1900 OR Y>2100 OR Y<>INT(Y) THEN ERX=1
1780 IF D<0 OR D>31 OR D<>INT(D) THEN ERX=1
1790 IF ERX=0 THEN 1798
1791 POKE 752,1:? "{UP}{inv} BAD DATE {/inv} Try again."
1792 FOR DL=1 TO 100:NEXT DL
1794 ? "{UP} "
1798 POKE 752,0:RETURN
1800 IF SKIP=1 THEN 1830
1810 POKE 752,1:POKE 764,255:? :? "Press any key to continue."
1820 IF PEEK(764)=255 THEN 1820
1830 POKE 752,0:POKE 764,255:RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: JULIAN.BAS.
Credits
- Program listing: Micro Julius (Julian Calendar) — program listing (Antic, June 1986 (Vol. 5, No. 2)) — Charles Postle
- Picture: Selection 6: the month containing the chosen date, with that day highlighted. (Captured from a copy with the first date built in.) — Charles Postle (program); screenshot by the site
- Antic, June 1986 - Vol. 5 No. 2: scan of the printed magazine, Micro Julius, by Charles Postle, pp. 39-40 (listing p. 104) — Charles Postle, 1986
- Antic disk, June 1986 - Vol. 5 No. 2: JULIAN.BAS (detokenized listing) — Charles Postle, 1986
