// Prints calendar for any month, 
//  any year from -5000000000 to +5000000000
// Starts with the current month
// To end program, just type <enter>
// For next or previous month, type + or -, then <enter>
// For any month/year type month, year <enter>
//  month is 1 through 12, year is all digits, e,g, 1975
//  negative years for BC.  Year 0 means current year.
// Calendar page may be printed - full sheet of paper.

dim dtarray (9)
dim dtarray2 (9)
dim daystr$ (32)
dim month$ (12)
dim day$   (7)
data "January", "February", "March", "April", "May", "June"
data "July","August","September","October", "November", "December"
data "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
for i = 0 to 11: read month$(i):next
for i = 0 to 6:  read day$(i):  next
day=makedatetime(-1,1,0)	// current month and year
date2 = makedatetime (-1,-1,0, 12)
dtarray2 = expanddatetime (date2)
current_date  = dtarray2 (2)
current_month = dtarray2 (1)
current_year  = dtarray2 (0)
//print "current date = ", current_date

100
graph landscape, noaxes, includexaxis=0, includeyaxis=0, nogrid, noborder
saveday=day
dtarray = expanddatetime (day)

month = dtarray (1)  // current month

  shape linecolor=(255,255,255) // white line to help auto scaling
  shape linestart=(5,8),lineend=(75,8),line
  shape linecolor=(0,0,0)

  y$ = str$(dtarray(0))		// format the year
if dtarray(0) >= 100 then goto 220  // normal years
if dtarray(0) < 0 then goto 200
  // put A.D. for years from 01 to 99
  y$ = str$(dtarray(0)) + " A.D."
  goto 220
200
  // put B.C. for negative years
  y$ = str$(-dtarray(0))+ " B.C."
220 
  m$=month$(month-1) + "  " + y$

// box for day of week titles
text datasize=8,x=40,y=2,string=m$
shape top=0,bottom=-5,left=5,right=75,filltype=none,rectangle

// Put day-of-week titles (SUN, MON, etc)
for i = 1 to 7
  text datasize=3,x=i*10,y=-3.5,string=day$(i-1)
next

// Draw the boxes with the days of the month.
shape radius = 5, filltype=none
week = 1
while dtarray (1) = month
  //print dtarray(2), dtarray(6), week
  shape center=(dtarray(6)*10, -week*10), rectangle
  d = dtarray (2) // day of month
  daystr$(d) = str$ (d)
  if (d = current_date) and (dtarray(0) = current_year) and (dtarray (1) = current_month ) then goto 2222
  text datasize=3,x=dtarray(6)*10+3,y=-week*10+2,string=daystr$(d)
  goto 2223
2222
  text datasize=4,x=dtarray(6)*10+3,y=-week*10+1.5,string=daystr$(d),color=(255,0,0),bold
2223
  dtarray (2) = dtarray(2)+1
  dtarray (8) = -1  // let system determine DST
  day = makedatetime (dtarray)
  dtarray=expanddatetime(day)
  if dtarray(6)=1 then week = week + 1
wend

// Change to another month/year
  print "Enter month (1-12), year -or- + or -"
  line input a$
  if a$ = "" then end  // quit program if nothing entered

  dtarray = expanddatetime (saveday)
  dtarray(2)=1  // day
  dtarray(3)=0
  dtarray(4)=0
  dtarray(5)=0
  dtarray(8)=-1 // system determines DST
if left$(a$, 1) <> "+" then goto 520
  dtarray(1) = dtarray(1)+1  // increment month if +
  goto 530
520
if left$(a$, 1) <> "-" then goto 540
  dtarray(1) = dtarray(1)-1  // decrement month if -
  if dtarray(1) >= 1 then goto 530
    dtarray(1) = 12
    dtarray(0) = dtarray(0)-1
    if dtarray (0) = 0 then dtarray(0) = -1 // skip year 0
530
  day = makedatetime(dtarray)
  goto 570
540
  input %a$; mm, yy    // look for month,year
  if mm < 1 or mm > 12 then mm = -1
  day=makedatetime(mm,1,yy)
570
  graph end  // erase graph so we can start a new one
  goto 100

