REM MAGDATS 3.0 - DATE EDIT ROUTINE FOR CP/M AND CBASIC
REM
REM PROPRIETARY SOFTWARE OF:
REM
REM    MICRO APPLICATIONS GROUP
REM    20201 SHERMAN WAY, SUITE 205
REM    CANOGA PARK, CA 91306
REM
REM  (C) COPYRIGHT 1979, 1980 MAG   ALL RIGHTS RESERVED
REM
%NOLIST
70000 MAGDATE.COPYRIGHT$="(C) COPYRIGHT 1979, 1980 MICRO APPLICATIONS GROUP"
      MAGDATE.COPYRIGHT$=""
      MAGDATE%(1) = 0
      IF MAGDATE%(8)= 1 THEN 70010 
70002 DIM MAGDATE.BT%(12)
      MAGDATE.BT%(1)=31:MAGDATE.BT%(2)=28:MAGDATE.BT%(3)=31
      MAGDATE.BT%(4)=30:MAGDATE.BT%(5)=31:MAGDATE.BT%(6)=30
      MAGDATE.BT%(7)=31:MAGDATE.BT%(8)=31:MAGDATE.BT%(9)=30
      MAGDATE.BT%(10)=31:MAGDATE.BT%(11)=30:MAGDATE.BT%(12)=31
70010 MAGDATE%(8) = 1
      IF MAGDATE$(1) = "C" THEN GOSUB 70200: GOTO 70099
      MAGDATE%(1) = 41:
70099 RETURN

70200 REM CALENDAR DATE TRANSLATION ROUTINE
      IF LEN(MAGDATE$(2)) = 6 THEN\
         MAGDATE$(9)=RIGHT$(MAGDATE$(2),2):MAGDATE$(2)=LEFT$(MAGDATE$(2),4)\
         +"19"+MAGDATE$(9):GOTO 70210
      IF LEN(MAGDATE$(2)) <> 8 THEN GOTO 70290
70210 MAGDATE$(6) = LEFT$(MAGDATE$(2),2)
      MAGDATE$(7) = MID$(MAGDATE$(2),3,2)
      MAGDATE$(8) = RIGHT$(MAGDATE$(2),4)
      GOSUB 70300:GOTO 70299
70290 MAGDATE%(1) = 51
70299 RETURN

70300 REM VALIDATION COMMON TO REPORT AND CALENDAR DATES
      IF MATCH("##",MAGDATE$(6),1) = 0 THEN GOTO 70390: REM NUMERIC TESTS
      IF MATCH("##",MAGDATE$(7),1) = 0 THEN GOTO 70390
      IF MATCH("####",MAGDATE$(8),1) = 0 THEN GOTO 70390
      MAGDATE%(3) = VAL(MAGDATE$(6)): REM MONTH
      MAGDATE%(4) = VAL(MAGDATE$(7)): REM DAY
      MAGDATE%(2) = VAL(MAGDATE$(8)): REM YEAR
      IF MAGDATE%(3) < 1 OR MAGDATE%(3) > 12 THEN GOTO 70390: REM RANGE TESTS
      IF MAGDATE%(4) < 1 OR MAGDATE%(4) > 31 THEN GOTO 70390
      IF MAGDATE%(2) < 1900 OR MAGDATE%(2) > 2173 THEN GOTO 70390
      GOSUB 70600: REM PERFORM LEAPYEAR TRANSLATION
      IF MAGDATE%(4) > MAGDATE.BT%(MAGDATE%(3)) THEN GOTO 70390
      GOTO 70399
70390 MAGDATE%(1) = 51
70399 RETURN

70600 REM LEAPYEAR COMPUTATION
      MAGDATE%(10) = (MAGDATE%(2) - MAGDATE%(2)/4*4+3)/ 4
      MAGDATE%(11) = (MAGDATE%(2) - MAGDATE%(2)/100*100+99)/ 100
      MAGDATE%(12) = (MAGDATE%(2) - MAGDATE%(2)/400*400+399)/400
      MAGDATE%(7) = 1 - MAGDATE%(10) + MAGDATE%(11) - MAGDATE%(12) + 1
      MAGDATE%(9) = MAGDATE%(7) - 1
      IF MAGDATE%(7)=1 THEN MAGDATE.BT%(2)=28 ELSE MAGDATE.BT%(2)=29
70699 RETURN
%LIST
