Google
 

Trailing-Edge - PDP-10 Archives - BB-M780B-SM - monitor-sources/datime.mac
There are 50 other files named datime.mac in the archive. Click here to see a list.
;<5.MONITOR>DATIME.MAC.3, 20-Jan-82 15:33:17, EDIT BY MAYO
;TCO 5.1651 - Have date-only IDTNC's not give time zone errors.
; UPD ID= 1504, SNARK:<5.MONITOR>DATIME.MAC.2,  27-Jan-81 14:03:11 by ZIMA
;TCO 5.1253 - Fix output for OT%SPA+OT%DAM and fix termination of null strings.
;<4.MONITOR>DATIME.MAC.7, 19-Oct-79 08:53:15, EDIT BY ENGEL
;TCO #4.2535 - RETURN -1 IN A & B FOR IDTNC WHEN CLOCK IS NOT ON YET (AT IDTN11)
;<4.MONITOR>DATIME.MAC.6, 13-Sep-79 06:44:46, EDIT BY R.ACE
;TAKE OUT EXTERN'S TO GET CHECKSUMS RIGHT ON .REL FILES
;<4.MONITOR>DATIME.MAC.5, 14-Aug-79 14:28:20, EDIT BY GRADY
;<4.MONITOR>DATIME.MAC.4,  2-Aug-79 10:57:08, EDIT BY GRADY
;tco 4.2369 - fix .odtim @ ott5+6 to not return "unprintable time zone" error
;<4.MONITOR>DATIME.MAC.3,  4-Mar-79 14:58:01, EDIT BY KONEN
;UPDATE COPYRIGHT FOR RELEASE 4
;<4.MONITOR>DATIME.MAC.2, 11-Oct-78 08:29:09, EDIT BY R.ACE
;TCO 4.2032 - FIX BUGS IN IDCNV JULIAN DAY VALIDATION
;<4.MONITOR>DATIME.MAC.1, 30-Sep-78 21:33:31, EDIT BY ZIMA
;TCO 4.2029 SPR 20-11913 MAKE IDTNC RETURN CURRENT DATE VALUES
;  WHEN IT%NDA GIVEN TO SUPPRESS DATE INPUT


;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1976,1977,1978,1979 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SEARCH PROLOG
	TTITLE DATIME

	SWAPCD

;TIME AND DATE ROUTINES

;JSYS'S HEREIN
; ODTIM
; IDTIM
; ODTNC
; IDTNC
; ODCNV
; IDCNV

	INTERN .ODTIM,.IDTIM,.ODTNC,.IDTNC,.ODCNV,.IDCNV ;JSYS'S
;INTERN ODTIMS,IDTIMS,ODTNCS,IDTNCS	;SUBR ENTRIES TO JSYS'S
;PARAMETERS


;THE FOLLOWING PARAMETERS CONTROL HANDLING OF DAYLIGHT SAVING TIME.
;THERE ARE THREE POSSIBILITIES:
;	1. DST NEVER USED (SET NEVDST INTO DSTFLG)
;	2. DST ALWAYS USED (SET ALLDST INTO DSTFLG)
;	3. DST USED ACCORDING TO SOME RULE (SET 0 INTO DSTFLG).
;IF THE RULE IS BEING USED, THE FOLLOWING PARAMETERS MAY BE SET:
;	1. DSTBGN - THE YEAR IN WHICH THE RULE BECAME EFFECTIVE
;	2. DSTON - THE LAST DAY OF THE YEAR ON WHICH DST MAY START.
;	   THE PRESENT ALGORITHM WILL START IT ON THE SUNDAY PRECEEDING
;	   THIS DAY.
;	3. DSTOFF - THE LAST DAY OF THE YEAR ON WHICH DST MAY END.
;	   THE PRESENT ALGORITHM WILL END IT ON THE SUNDAY PRECEEDING
;	   THIS DAY.
;IF THIS IS INSUFFICIENT TO DESCRIBE THE CURRENT RULE, THE CODE WILL
;HAVE TO BE CHANGED.

	ALLDST==1B0		;DST ALWAYS IN EFFECT
	NEVDST==1B1		;DST NEVER IN EFFECT
DSTFLG::0			;DST FLAG
DSTBGN::^D1975
DSTON::	^D<31+29+31+30>-1	;LAST SUNDAY IN APRIL
DSTOFF:^D<31+29+31+30+31+30+31+31+30+31>-1
				;LAST SUNDAY IN OCTOBER

DWFUDG==2			;CONSTANT TO NORMALIZE DAY OF WEEK
				; = DAY OF WEEK OF 17 NOV 1858


;ACCUMULATORS

Z=0
A=1
B=2
C=3
D=4
E=5
F=6
G=7
AA=10
BB=11
CC=12
DD=13
EE=14
FF=15
GG=16
P=17

;HALF-WORD BIT SYMBOLS

B0==1B18
B1==1B19
B2==1B20
B3==1B21
B4==1B22
B5==1B23
B6==1B24
B7==1B25
B8==1B26
B9==1B27
B10==1B28
B11==1B29
B12==1B30
B13==1B31
B14==1B32
B15==1B33
B16==1B34
B17==1B35
REPEAT 0, <

ODTIM

	OUTPUT DATE AND TIME

	CONVERTS INTERNAL DATE AND TIME TO TEXT

TAKES:	1: TENEX DESTINATION DESIGNATOR
	2: LEFT HALF: INTERNAL DATE
	   RIGHT HALF: INTERNAL TIME
	   OR ENTIRE WORD -1 TO USE CURRENT DATE AND TIME
	3: FORMAT FLAGS, DESCRIBED BELOW

RETURNS: +1 ALWAYS: UPDATED STRING POINTER (IF PERTINENT) IN 1.

	GENERATES ILLEGAL INSTRUCTION PSEUDO-INTERRUPT ON
	ERROR CONDITIONS GIVEN BELOW.
ODTIM FORMAT FLAGS (AC 3):

    B0: OFF, OUTPUT DATE
	ON, OMIT DATE AND IGNORE B1-B8
    B1: ON, OUTPUT DAY OF WEEK
	OFF, OMIT DAY OF WEEK AND IGNORE B4
    B2: ON, USE FULL TEXT FOR WEEKDAY
	OFF, USE 3-LETTER ABBREVIATION FOR WEEKDAY
    B3: ON, OUTPUT MONTH AS NUMBER AND IGNORE B4
	OFF, OUTPUT MONTH AS TEXT
    B4: ON, USE FULL TEXT FOR MONTH
	OFF, USE 3-LETTER ABBREVIATION FOR MONTH
    B5: ON, OUTPUT 4-DIGIT YEAR
	OFF, OUTPUT 2-DIGIT YEAR IF BETWEEN 1900 AND 1999
    B6: ON, OUTPUT DAY OF MONTH AFTER MONTH
	OFF, OUTPUT DAY OF MONTH BEFORE MONTH
    B7 AND B8: DATE PUNCTUATION CONTROL:
	BOTH OFF, PUNCTUATE WITH DASHES, AS 13-APR-70
	B7 ON, PUNCTUATE WITH SPACES, AS 13 APR 70.
	       A COMMA IS ALSO USED IF B6 IS ON, AS APRIL 13, 1970
	B8 ON, PUNCTUATE WITH SLASHES, AS 5/13/70
	BOTH B7 AND B8 ON, UNSPECIFIED
    B9: OFF, OUTPUT TIME
	ON, OMIT TIME AND IGNORE B10-B13
   B10: OFF, INCLUDE SECONDS, PRECEDED BY A COLON
	ON, OMIT SECONDS
   B11: OFF, USE 24-HOUR TIME
	ON, USE 12-HOUR TIME AND AM-PM
   B12: OFF, COLON BETWEEN HOURS AND MINUTES
	ON, NO COLON
   B13: OFF, NO TIME ZONE GARBAGE
	ON, ADD "-" AND TIME ZONE TO TIME, EG "-EDT" OR "-PST"
   B17: OFF, COLUMNATE: USE LEADING SPACES AND ZEROES SO THAT
	TTME AND DATE PRINTOUT IS CONSTANT-WIDTH REGARDLESS OF THE
	PARTICULAR DATE AND TIME (NOTE: FULL MONTH AND WEEKDAY TEXTS
	ARE NOT COLUMNATED).
	ON, DON'T COLUMNATE.
	NOTE: COLUMNATION WILL GENERALLY BE DESIRED IF THE PRINTOUT
	IS PART OF A TABLE, BUT NO COLUMNATION PRODUCES A
	SLIGHTLY BETTER LOOKING PRINTOUT WHEN PART OF A SENTENCE.

FOR CONVENIENCE, -1 IN 3 IS TAKEN AS EQUIVALENT TO 336001000000,
WHICH PRODUCES, FOR EXAMPLE, FRIDAY, APRIL 13, 1970 1:06:03.

EXAMPLES:
    CONTENTS OF 3	    TYPICAL TEXT
	0			 3-APR-70  1:06:03
	202201000000		FRI 3 APR 70 1:06
	336321000000		FRIDAY, APRIL 3, 1970 1:06AM-EST
	041041000000		3/4/70 106:03
	041040000000		 3/04/70  106:03
ODTIM ERROR MNEMONICS:

STIMEX:	SYSTEM HAS NO DATE AND TIME
TIMEX1:	ILLEGAL TIME (GREATER THAN 24 HOURS)
ODCNV ERRORS (LIST THEM ALL HERE)
ODTNC ERRORS
FILE ERRORS
DESXN ERRORS

>




;NOTE: JSYS'S USING STRING I/O CANNOT BE NESTED BECAUSE STRING
;POINTER WOULD ALWAYS REFER TO MONITOR ADDR SPACE EVEN IF OUTER JSYS
;CALLED FROM USER SPACE.
;HENCE SUBROUTINE ENTRIES ARE USED FOR ODTNC AND IDTNC WHEN USED
;IN ODTIM AND IDTIM, AND SUBROUTINE ENTRIES ARE ALSO PROVIDED
;TO ODTIM AND IDTIM FOR USE ELSEWHERE IN THE MONITOR.

;ODTIM JSYS

.ODTIM:	MCENT			;BECOME SLOW, ETC.
	CALL ODTIMS		;ODTIM SUBROUTINE
	MRETNG			;RETURN TO CALLER

;ODTIM SUBROUTINE, FOR ODTIM JSYS
; AND POSSIBLE OTHER FUTURE USES IN MONITOR INVOLVING STRING
; IN USER SPACE.
;TAKES: CALLER'S A: DESTINATION
;	ACTUAL B: DATE & TIME OR -1
;	ACTUAL C: FORMAT OPTION FLAGS
;RETURNS +1: WITH CALLERS A UPDATED (IF STRING POINTER)
;CLOBBERS MOST OR ALL OF AC'S B-DD.

ODTIMS:	PUSH P,C		;SAVE FORMAT OPTION FLAGS
	SETZ D,			;DEFUALT ZONE & DAYLIGHT STUFF
	ODCNV			;CONVERT INTERNAL TO LOCAL DATE & TIME
	POP P,F			;GET FORMAT OPTION FLAGS BACK INTO F
	CALL ODTNCS		;SUBR ENTRY TO ODCNV JSYS (BELOW)
				;CONVERTS LOCAL DATE & TIME TO STRING
	RET			;RETURN
REPEAT 0, <

IDTIM

	INPUT DATE AND TIME

	CONVERTS TEXT TO INTERNAL DATE AND TIME

TAKES: 1: TENEX SOURCE DESIGNATOR
       2: FORMAT OPTION FLAGS, DESCRIBED BELOW, 0 FOR NORMAL CASE

RETURNS: +1: FAIL, ERROR NUMBER IN 2,
		   UPDATED STRING PTR (IF PERTINENT) IN 1
	 +2: SUCCESS, 1: UPDATED STRING PTR (IF PERTINENT)
		      2: LH: DATE IN SYSTEM INTERNAL FORMAT (GREENWICH)
			 RH: TIME IN SYSTEM INTERNAL FORMAT
			     (GREENWICH MEAN TIME)

IDTIM DOES NOT ADMIT OF DOING CONVERSIONS FOR OTHER THAN THE
LOCAL TIME ZONE OR FOR DAYLIGHT SAVINGS TIME IF APPROPRIATE, EXCEPT IF
THE INPUT STRING CONTAINS A TIME ZONE CODE.  HOWEVER, THE CALLER MAY
ADD OR SUBTRACT HOURS TO ADJUST TO OTHER TIME ZONES; HE MAY
DETERMINE THE LOCAL TIME ZONE USING "ODCNV" (BELOW).

IDTIM DOES NOT ADMIT OF INPUTTING EITHER THE DATE OR THE TIME ALONE.
SEE IDTNC, BELOW, FOR THIS.
IDTIM FORMAT OPTIONS (AC 2):

    B1: ON, DISALLOW NUMERIC MONTH IN INPUT AND IGNORE B2-B3
    B2: OFF, IF MONTH IS NUMERIC, AS IN "1/2/70", CONSIDER
	     THE FIRST NUMBER TO BE THE MONTH
	ON, CONSIDER THE SECOND NUMBER TO BE THE MONTH. IE "1/2/70"
	    MEANS 1 FEB NOT JAN 2, AS IS CUSTOMARY IN ENGLAND.
    B3: OFF, IF AN INVALID DATE CAN BE INTERPRETED SUCESSFULLY BY
             ASSUMING MONTH AND DAY ARE IN OPPOSITE ORDER THAN
             THAT SPECIFIED BY B2, INTERPRET IT THUS.
	     THIS WOULD APPLY, FOR EXAMPLE, TO "31/1/70" WITH B2 OFF.
	ON, GIVE AN ERROR RETURN FOR SUCH DATES.
    B7 AND B8 GOVERN INCLUSION OF SECONDS (PRECEDED BY COLON)
	      IN TIME.
              BOTH OFF, SECONDS ARE OPTIONAL.
              B7 ON, SECONDS ILLEGAL.
              B8 ON, SECONDS MANDATORY.
    B9 AND B10 GOVERN USE OF COLON BETWEEN HOURS AND MINUTES.
	       BOTH OFF, OPTIONAL
	       B9 ON, ILLEGAL.
	       B10 ON, MANDATORY.
    B11 AND B12: WHEN BITS 7 THRU 10 ARE ALL OFF, THESE
		 BITS DETERMINE WHETHER A TIME WITH ONE COLON IS
		 INTERPRETED AS HOURS AND MINUTES OR HOURS, MINUTES,
		 AND SECONDS WITH NO COLON BETWEEN THE FORMER.
		 BOTH OFF, TAKE AS HH:MM IF FIRST FIELD IS SMALL ENOUGH,
			   ELSE AS HHMM:SS.
		 B11 ON, ALWAYS TAKE AS HHMM:SS.
		 B12 ON, ALWAYS TAKE AS HH:MM (GIVING AN ERROR IF
			 FIRST FIELD IS TOO BIG). THIS DIFFERS FROM
			 B7 ON IN THAT SECONDS CAN BE INCLUDED IF
			 PRECEDED BY A SECOND COLON.
   B14: ON TO DISALLOW 24-HOUR TIME AND MAKE AM-PM MANDATORY
   B15: ON TO DISALLOW AM-PM
   B16: ON TO DISALLOW TIME ZONE


IDTIM ERROR MNEMONICS

IDTNC ERRORS
IDCNV ERRORS
FILE ERRORS
DESXN ERRORS

>
;IDTIM JSYS

.IDTIM:	MCENT
	CALL IDTIMS		;IDTIM SUBROUTINE
	 JRST [	UMOVEM B,B	;ERROR. RETURN CODE IN B
		MOVE A,B	;GET ERROR CODE IN A
		EMRETN()]	;GIVE +1 ERROR RETURN TO CALLER
	UMOVEM B,B		;RETURN INTERNAL DATE & TIME IN B
	SMRETN			;RETURN +2

;IDTIM SUBROUTINE, FOR IDTIM JSYS AND POSSIBLE OTHER USES 
; (SEE NOTES WITH ODTIM)
;TAKES: CALLERS A: SOURCE
;	ACTUAL B: FORMAT OPTION FLAGS
;RETURNS +1: ERROR CODE IN ACTUAL B, CALLERS A UPDATED
;	 +2: DATE & TIME IN ACTUAL B, CALLERS A UPDATED
;CLOBBERS C-DD.

IDTIMS:	CALL IDTNCS		;SUBR ENTRY TO IDTNC JSYS (BELOW)
				;INPUTS DATE & TIME AND RETURNS AS LOCAL NUMBERS
	 RET			;ERROR. # IN B.
	IDCNV			;CONVERT LOCAL TO INTERNAL
	 RET			;ERROR, # IN B.
	RETSKP
;ODTNC
;	OUTPUT DATE AND/OR TIME WITHOUT CONVERSION FROM INTERNAL

;A SUBSET OF ODTIM, USED INTERNALLY BY ODTIM.

;TAKES:	1: TENEX DESTINATION DESIGNATOR
;	2: LH: REAL YEAR
;	   RH: MONTH (JANUARY=0)
;	3: LH: DAY OF MONTH
;	   RH: DAY OF WEEK IF PRINTOUT THEREOF REQUESTED
;	4: LH: NEEDED ONLY IF TIME ZONE PRINTOUT REQUESTED:
;	       B1: ON FOR DAYLIGHT SAVINGS
;	       B12-17: TIME ZONE
;	   RH: LOCAL TIME (SECONDS SINCE MIDNITE)
;	5: FORMAT OPTION FLAGS, SAME AS FOR ODTIM (ABOVE).
;	   NOTE: THE ONLY TIME ZONES WHICH CAN BE PRINTED (FLAG B13)
;	   ARE THOSE IN THE USA AND GREENWICH.

;RETURNS +1 WITH UPDATED STRING POINTER (IF PERTINENT) IN 1.
;TRAPS ON ERRORS.

;ERROR MNEMONICS

;DATEX1: ILLEGAL YEAR
;DATEX2: MONTH TOO LARGE
;DATEX3: DAY OF MONTH TOO LARGE
;DATEX4: DAY OF WEEK TOO LARGE
;ZONEX1: ILLEGAL TIME ZONE VALUE (NOT BETWEEN -12 AND 12)
;ODTNX1: UNPRINTABLE TIME ZONE
;FILE ERRORS
;DESXN ERRORS


;ODTNC JSYS

.ODTNC:	MCENT
	UMOVE F,E
	CALL ODTNCS		;CALL ODTNC SUBROUTINE (NEXT IN LISTING)
	MRETNG			;GIVE SUCCESSFUL RETURN
;ODTNCS
;ODTNC SUBROUTINE FOR ODTNC AND ODTIM JSYS'S

;CALL: ALL AC'S ARE ACTUAL EXCEPT THOSE NOTED AS "CALLER" WHICH ARE
;	USER IF LAST JSYS WAS FROM USER SPACE.
;TAKES:	CALLER A: DESTINATION
;	B: YEAR,,MONTH
;	C: MONTHDAY,,WEEKDAY
;	D: TIME STUFF
;	F: FORMAT OPTION FLAGS
;RETURNS +1: ON SUCCESS WITH CALLER A UPDATED,
;	B-E,G,AA,BB,DD CLOBBERED
;TRAPS ON ERRORS

;INTERNAL AC USE
;	D,E,AA:	ARGS FROM B,C,D
;	BB: LOCAL TIME FROM RH D, LH 0.

ODTNCS:	SE1CAL
	MOVE DD,P		;SAVE PD LEVEL TO RESTORE BEFORE ERROR RETURN
	CAMN F,[-1]
	HRLZI F,336001		; DEFAULT FORMAT FOR -1
	MOVE AA,D		;TIME STUFF TO AA
	TLZ AA,B3		;DISALLOW JULIAN FORMAT
	MOVEI BB,(D)		;TIME ONLY, WITH LH 0, TO BB
	CALL CKYMDT		;CHECK MOST ARGUMENTS. THIS SUBR IS WITH
				;"IDCNV" BELOW. USES B,C,AA.
	 JRST ODTNCE		;BAD ARGUMENT. ERROR CODE IN B.
	MOVE D,B		;LOCAL YEAR,,LOCAL MONTH TO D.
	MOVE E,C		;LOCAL DAY OF MONTH,,DAY OF WEEK TO E.
	MOVEI G,^D10		;SET G FOR USE IN C FOR MOST NOUTS: DECIMAL,
	TLNN F,B17		;COLUMNATION SUPPRESSED?
	HRLI G,B2+2		;NO, 2 COLUMNS, LEADING SPACE.
	TLNE F,B0		;ARE WE GOING TO PRINT DATE?
	JRST OTT1		;NO, DATE SUPPRESSION REQUESTED.
;ODTNCS...
;DATE

	TLNN F,B1
	JRST ODB2

;DAY OF WEEK

	HRRZ B,E
	CAIL B,7
	JRST [	MOVEI B,DATEX4	;"DAY OF WEEK TOO LARGE"
		JRST ODTNCE]
	PUSH P,E		;SAVE E
	HRRZS E			;GET RID OF HIGH ORDER BITS
	HRROI B,[ASCIZ /Mon/
		ASCIZ /Tue/
		ASCIZ /Wed/
		ASCIZ /Thu/
		ASCIZ /Fri/
		ASCIZ /Sat/
		ASCIZ /Sun/](E)
	TLNE F,B2		;ON FOR VERBOSE
	HRRO B,[[ASCIZ /Monday,/]
		[ASCIZ /Tuesday,/]
		[ASCIZ /Wednesday,/]
		[ASCIZ /Thursday,/]
		[ASCIZ /Friday,/]
		[ASCIZ /Saturday,/]
		[ASCIZ /Sunday,/] ] (E)
	POP P,E			;RESTORE E
	CALL SOUTA
	MOVEI B," "		;ALWAYS A SPACE AFTER WEEKDAY
	CALL BOUTA
;ODTNCS...
;DAY # IF BEFORE MONTH

ODB2:	TLNE F,B6
	JRST ODB3
	HLRZ B,E
	ADDI B,1		;REAL DAY IS ARG +1.
	MOVE C,G
	CALL NOUTXX

;SEPERATOR

	CALL ODTMSP		;DASH, SPACE, OR SLASH, DEPENDING ON FLAGS.

;MONTH

ODB3:	TLNN F,B3
	JRST ODB3A

;MONTH AS NUMBER

	HRRZ B,D
	ADDI B,1
	MOVE C,G		;NOUT FORMAT
	TLNN F,B6		;IF DAY # WAS FIRST,
	TLO C,B3		;USE LEADING 0 NOT SPACE FOR MONTH
	CALL NOUTXX		;MONTH
	JRST ODB3B

;MONTH AS CONCISE OR VERBOSE TEXT

ODB3A:	PUSH P,D		;SAVE D
	HRRZS D			;GET RID OF HIGH ORDER BITS
	HRROI B,[ASCIZ /Jan/
		ASCIZ /Feb/
		ASCIZ /Mar/
		ASCIZ /Apr/
		ASCIZ /May/
		ASCIZ /Jun/
		ASCIZ /Jul/
		ASCIZ /Aug/
		ASCIZ /Sep/
		ASCIZ /Oct/
		ASCIZ /Nov/
		ASCIZ /Dec/ ] (D)
	TLNE F,B4		;ON FOR VERBOSE
	HRRO B,[[ASCIZ /January/]
		[ASCIZ /February/]
		[ASCIZ /March/]
		[ASCIZ /April/]
		[ASCIZ /May/]
		[ASCIZ /June/]
		[ASCIZ /July/]
		[ASCIZ /August/]
		[ASCIZ /September/]
		[ASCIZ /October/]
		[ASCIZ /November/]
		[ASCIZ /December/] ] (D)
	POP P,D			;RESTORE D
	CALL SOUTA

;SEPERATOR

ODB3B:	CALL ODTMSP		;DASH, SLASH, OR SPACE PER FLAGS
;ODTNCS...
;DAY OF MONTH IF AFTER MONTH

	TLNN F,B6
	JRST ODB5
	HLRZ B,E
	ADDI B,1
	MOVE C,G
	TLNE F,B3		;IF MONTH WAS NUMBER,
	TLO C,B3		;USE LEADING 0 NOT SPACE
	CALL NOUTXX

;SEPERATOR: FIRST A COMMA IF MONTH WAS VERBOSE TEXT

	TXNN F,OT%NMN		;NO COMMA IF NUMERIC MONTH
	TXNN F,OT%FMN+OT%SPA	;BUT DO ONE IF FULL NAME OR OT%SPA
	 JRST .+3		;SKIP COMMA
	MOVEI B,","
	CALL BOUTA
	CALL ODTMSP		;DASH, SLASH, OR SPACE PER FLAGS

;YEAR

ODB5:	HLRZ B,D
	TLNE F,B5
	JRST ODB5A		;VERBOSE YEAR REQUESTED
	IDIVI B,^D100		;SEPERATE CENTURY AND YEAR WITHIN CENTURY
	EXCH B,C		;CONCISE YEAR: LAST 2 DIGITS ONLY
	CAIE C,^D19
	HLRZ B,D		;MAKE YEAR ALWAYS VERBOSE IF NOT 19XX
ODB5A:	MOVE C,[1B2+1B3+2B17+^D10] ;NOUT FORMAT: 2 COLS, LEADING 0S.
	CAIL B,^D100
	HRLI C,B2+B3+4		;BUT USE 4 COLS IF VERBOSE
	CALL NOUTXX

;SPACE BETWEEN DATE AND TIME,
;NOT PRINTED IF EITHER IS SUPPRESSED.

	TLNE F,B9
	JRST OTT1
	MOVEI B," "
	CALL BOUTA
;ODTNCS...

OTT1:	TLNE F,B9
	JRST ODT8		;TIME SUPPRESSED

;TIME

	MOVEI D,(BB)		;MASK RH: LOCAL TIME IN MIUTES SINCE MIDNITE
	IDIVI D,^D3600
	MOVE B,D
	TLNN F,B11		;PRINTING 12-HOUR TIME?
	JRST OTT2		;NO
	CAIGE B,1		;12-HOUR PRINTOUT IS ALWAYS BETWEEN 1:00:00
	ADDI B,^D12		;...AND 12:59:59. SO ADD 12 IF BEFORE 1:00:00
	CAILE B,^D12
	SUBI B,^D12		;SUBTRACT 12 HOURS IF AFTER 12:59:59
OTT2:	MOVE C,G		;NOUT FORMAT SET UP AT ENTRY TO ODTIM.
	TLNN F,(1B11)		;PRINTING AM/PM?
	TLO C,(1B2+1B3+2B17)	;NO, USE LEADING 0 ON HOURS
	CALL NOUTXX		;PRINT HOURS
	MOVEI B,":"
	TLNN F,B12		;COLON REQUESTED BETWEEN HOURS AND MINUTES?
	CALL BOUTA		;YES
	MOVE D,E
	IDIVI D,^D60
	MOVE B,D
	TLO C,B2+B3+2		;ALWAYS LEADING 0 ON MINUTE AND SECONDS
	CALL NOUTXX		;PRINT MINUTES
	TLNE F,B10
	JRST OTT4		;SECONDS SUPPRESSED
	MOVEI B,":"
	CALL BOUTA		;SECONDS ARE ALWAYS PRECEDED BY COLON
	MOVE B,E
	CALL NOUTXX		;SECONDS
;ODTNCS...

OTT4:	TLNN F,B11		;12-HOUR TIME REQUESTED?
	JRST OTT5		;NO
	HRROI B,[ASCIZ /AM/]	;YES, PRINT AM, PM, N, OR M.
	CAIL BB,^D<12*3600>
	HRROI B,[ASCIZ /PM/]
	CAIN BB,^D<12*3600>
	HRROI B,[ASCIZ /N/]	;"N" FOR NOON
	CAIN BB,0
	HRROI B,[ASCIZ /M/]	;"M" FOR MIDNITE
	CALL SOUTA
OTT5:	TLNN F,B13		;PRINTING TIME ZONE REQUESTED?
	JRST OTT6		;NO
	LDB E,[POINT 6,AA,17]	;TIME ZONE
	JUMPE E,[HRROI B,[ASCIZ /-GMT/]
		TLNE AA,B1	;B1 OF ARG FROM D ON FOR DAYLIGHT
		HRROI B,[ASCIZ /-GDT/] ;"GREENWICH DAYLIGHT TIME" !?
		JRST OTT5A]
	CAIG E,^D11		;IS TIME ZONE IN RANGE FOR WHICH WE HAVE TEXTS?
	CAIGE E,^D4
	jrst ott6		;if time zone is unprintable, don't print it
	HRROI B,[ASCIZ /-AST/	;ATLANTIC
		ASCIZ /-EST/	;EASTERN
		ASCIZ /-CST/	;CENTRAL
		ASCIZ /-MST/	;MOUNTAIN
		ASCIZ /-PST/	;PACIFIC
		ASCIZ /-YST/	;YUKON
		ASCIZ /-HST/	;ALASKA-HAWAII
		ASCIZ /-BST/]-4(E) ;BERING

	TLNE AA,B1		;DAYLIGHT SAVINGS IN EFFECT FOR THIS DATE?
	HRROI B,[ASCIZ /-ADT/	;ATLANTIC
		ASCIZ /-EDT/	;EASTERN
		ASCIZ /-CDT/	;CENTRAL
		ASCIZ /-MDT/	;MOUNTAIN
		ASCIZ /-PDT/	;PACIFIC
		ASCIZ /-YDT/	;YUKON
		ASCIZ /-HDT/	;ALASKA-HAWAII
		ASCIZ /-BDT/]-4(E) ;BERING
OTT5A:	CALL SOUTA
OTT6:	TLNE F,B11		;12-HOUR TIME REQUESTED?
	TLNE F,B17		;COLUMNATION SUPPRESSED?
	JRST OTT9		;NO OR YES
;IF N FOR NOON OR M FOR MIDNITE PRINTED WITH COLUMNATION,
;PRINT SPACE AFTER TIME ZONE, BECAUSE SPACE BEFORE TIME ZONE
;IS A FORMAT THAT CAN'T BE TYPED INTO "IDTIM".
	MOVEI B," "
	CAIE BB,^D<12*3600>
	CAIN BB,0
	CALL BOUTA
OTT9:
;ODTNCS...
;EXIT

ODT8:	UMOVE A,1		;FETCH USER'S OUTPUT DESIGNATOR
	TXC F,OT%NDA+OT%NTM	;CHECK FOR BOTH NO DATE AND
	TXCN F,OT%NDA+OT%NTM	; NO TIME BEING SET
	TLNN A,777777		;PLUS A STRING POINTER DESIGNATOR
	 RET			;NOT THE ABOVE, DONE
	TLC A,777777		;CHECK FOR AND CONVERT
	TLCN A,777777		;-1,,ADR
	HRLI A,(<POINT 7,0>)	;MAKE REAL BYTE POINTER
	SETZ B,			;GET A NULL
	XCTBU [	IDPB B,A]	;END THE STRING PROPERLY
	RET			;AND DONE

ODTNCC:	MOVE B,C		;HERE WHEN ERROR CODE IS IN C, AS AFTER "NOUT"

;ODTNC ERROR RETURN.  ERROR CODE IN B.

ODTNCE:	MOVEM B,LSTERR		;SAVE ERROR CODE IN PSB FOR "GETER"
	MOVE P,DD		;CLEAR PD
	JRST ITRAP


;SUBROUTINE TO OUTPUT APPROPRIATE SEPERATOR PER FLAGS 7 AND 8.

ODTMSP:	MOVEI B,"-"
	TLNE F,B7
	MOVEI B," "
	TLNE F,B8
	MOVEI B,"/"
	CALLRET BOUTA

;SOUTA
;MONITOR TO CALLER'S ADDRESS SPACE STRING OUTPUT SUBROUTINE
;FOR ODTNCS
;B POINTS TO SOURCE STRING; LH -1 => 440700
;CALLERS A IS DESTINATION. BOTH ARE UPDATED.

SOUTA:	PUSH P,C
	HLRZ C,B
	CAIN C,-1
	HRLI B,<POINT 7,0,-1>B53
	MOVE C,B
SOUTA1:	ILDB B,C
	JUMPE B,[MOVE B,C
		POP P,C
		RET]
	CALL BOUTA
	JRST SOUTA1
REPEAT 0, <

IDTNC

	INPUT DATE AND/OR TIME WITHOUT CONVERSION TO INTERNAL

THIS JSYS IS A SUBSET OF IDTIM AND WILL ONLY BE OF INTEREST TO THOSE
WHO WISH TO INPUT THE DATE AND TIME WITHOUT CONVERTING TO
INTERNAL, OR WHO WISH TO INPUT THE TWO QUANTITIES SEPERATELY, EG
BECAUSE OF INTERVENING TYPEOUT.  (IDTIM CANNOT iNPUT EITHER
ALONE BECAUSE IT IS IMPOSSIBLE TO CONVERT ONE TO INTERNAL WITHOUT
THE OTHER.)  IDTNC RETURNS VALUES SUITABLE FOR USE AS ARGUMENTS TO
IDCNV.  IDTNC IS USED INTERNALLY BY IDTIM.

TAKES: 1: TENEX SOURCE DESIGNATOR
       2: FORMAT OPTION FLAGS, DESCRIBED BELOW

RETURNS: +1: FAILURE, ERROR CODE IN 1,
		      UPDATED STRING POINTER (IF PERTINENT) IN 4
	 +2: SUCCESS, VALUES IN ACCUMULATORS:
		1: UPDATED STRING POINTER IF PERTINENT
	        IF DATE INPUT WAS NOT SUPPRESSED:
		   2: LH: REAL YEAR
		      RH: MONTH (JANUARY=0)
		   3: LH: DAY OF MONTH (FIRST DAY=0)
		      RH: DAY OF WEEK (MONDAY=0)
		IF TIME INPUT WAS NOT SUPPRESSED:
		   4: RH: TIME AS SECONDS SINCE MIDNIGHT
		      LH: B0: OFF UNLESS A TIME ZONE WAS INPUT
		          B1: ON IF A DAYLIGHT SAVING TIME ZONE
			      (EG EDT) WAS INPUT.
		          B2: OFF UNLESS A TIME ZONE WAS INPUT
		          B12-17: TIME ZONE, IF ONE WAS INPUT, ELSE
			          LOCAL TIME ZONE.
			          (SEE DESCRIPTION OF TIME ZONeS UNDER
			          IDCNV)
			  (REDUNDANT BITS B0 AND B2 ARE FOR
			  COMPATIBILITY WITH ODCNV)

IDTNC FORMAT OPTION FLAGS (AC 2):

    ALL OF THOSE DESCRIBED ABOVE UNDER IDTIM APPLY, AND ALSO:

    B0 ON, DON'T INPUT DATE, IGNORE B1-B3
    B6 ON, DON'T INPUt TIME, IGNORE B8-B16

IDTNC ERROR MNEMONICS:

DILFX1: ILLEGAL FORMAT FOR DATE
TILFX1: ILLEGAL FORMAT FOR TIME
NOTE: IDTNC DOES NOT DETECT CERTAIN ERRORS IN DATE INPUT, SUCH AS
DAY 31 OF A 30-DAY MONTH.  SUCH ERRORS ARE DETECTED IN IDCNV.
>
;IDTNC JSYS

.IDTNC:	MCENT
	CALL IDTNCS		;IDTNC SUBROUTINE, NEXT
	 JRST [	UMOVEM B,B	;ERROR, RETURN CODE IN CALLER'S B.
		MOVE A,B	;GET ERROR CODE IN A
		EMRETN()]	;GIVE +1 ERROR RETURN TO CALLER
	UMOVEM B,B		;RETURN RESULTS
	UMOVEM C,C
	UMOVEM D,D
	SMRETN			;GIVE SKIP RETURN


;IDTNCS
;IDTNC SUBROUTINE, FOR IDTIM AND IDTNC JSYS'S

;CALL SAME AS JSYS EXCEPT ALL AC'S ACTUAL EXCEPT A IS CALLER
;	(IE CALLER OF JSYS THAT CALLS SUBROUTINE)
;CLOBBERS B-DD.

;IDTNC INTERNAL AC USE
;	A: SOURCE DESIGNATOR
;	B,C,D,E: TEMPS
;	F: FLAGS
;	G: LAST CHARACTER READ
;	AA, BB, CC: WHAT WILL BE RETURNED IN B, C, D
;	DD: SAVED P
;IDTNCS

IDTNCS:	MOVE DD,P		;SAVE P: USED WHEN MAKING AN ERROR RETURN
	MOVE F,B		;FLAGS REMAIN IN F THROUGHOUT
	MOVEI G," "		;G CONTAINS CHARACTER: PRESET TO SPACE SO
				;"GNSC" SUBR WILL READ FIRST CHARACTER
	TLNE F,B0		;ON TO SUPPRESS DATE INPUT
	JRST ITN1		;DATE INPUT SUPPRESSED

;INPUT DATE

	CALL MONTH		;TRY INPUTTING ALPHA MONTH
	JRST IDN2		;NOT A LETTER, GO TRY NUMBER

;PROCESS REST OF DATE WHICH BEGINS WITH ALPHABETIC MONTH

	CALL DNIN		;INPUT NUMBER FOR DAY OF MONTH -1 INTO B
	HRL BB,B		;RETURN DAY OF MONTH IN LH C
	CALL GNSC		;NON-SPACE CHARACTER
	CAIN G,","		;COMMA ALLOWED IN THIS CONTEXT ONLY
	JRST [	CALL IDCHAR	;PASS THE COMMA. "YEAR" PASSES SPACES.
		JRST .+2]
	CALL IDSEP		;SEPERATING DASH OR SLASH AND SPACES
	CALL YEAR		;INPUT YEAR
	JRST IDN7

;DATE MUST BEGIN WITH A NUMBER

IDN2:	CALL DNIN		;READ NUMBER: VALUE-1 TO B
	HRL BB,B		;STORE VALUE IN DAY OF MONTH
	CALL IDSEP		;SEPERATING DASH OR SLASH AND SPACES
	CALL MONTH		;ALPHANUMERIC MONTH NEXT?
	JRST IDN3		;NO, GO TRY NUMBER
	CALL YEAR		;INPUT YEAR
	JRST IDN7
;IDTNCS...
;SECOND FIELD OF DATE MUST ALSO BE A NUMBER

IDN3:	TLNE F,B1		;NUMERIC MONTH ALLOWED?
	JRST IDILF		;NO, "ILLEGAL FORMAT" ERROR
	CALL DNIN		;GET SECOND NUMBER -1 INTO B.
	HLRZ C,BB		;FIRST NUMBER TO C
	TLNE F,B2		;IS FIRST NUMBER SUPPOSED TO BE MONTH?
	EXCH C,B		;NO, SWAP. MONTH TO C, DAY TO B.
	CAIG C,^D11		;IS "MONTH" TOO LARGE
	JRST IDN4		;OK
	CAIG B,^D11		;IS OTHER NUMBER ALSO TO LARGE TO BE MONTH?
	TLNE F,B3		;WILL CALLER LET US SWAP THEM?
	JRST IDILF		;YES OR NO, ERROR.
	EXCH B,C
IDN4:	HRR AA,C		;RETURN MONTH IN RH B
	HRL BB,B		;RETURN DAY IN RH C
	CALL IDSEP		;SEPERATING SPACES, DASH OR SLASH, SPACES.
	CALL YEAR		;GET YEAR
IDN7:	TLNE F,B6		;ON TO SUPPRESS TIME INPUT
	JRST IDTNC8		;TIME INPUT SUPPRESSED

;SEPERATOR BETWEEN DATE AND TIME: ONE TAB, ANY NUMBER OF SPACES.

	CALL GNSC
	CAIN G,11		;ASCII TAB
	CALL IDCHAR
;IDTNCS...
;INPUT TIME

ITN1:	TLNE F,B6
	JRST IDTNC8		;BOTH TIME AND DATE SUPPRESSED, JSYS IS NOP.
	SETZ E,			;ZERO FOR SECONDS IF OMITTED
	CALL IDNIN		;PASS SPACES, READ NUMBER
	 JRST ITILF		;NO NUMBER, "ILLEGAL FORMAT FOR TIME" ERROR
	PUSH P,B
;THIS NUMBER MAY BE HOURS OR HOURS AND MINUTES.
	CAILE B,^D2400		;BUT CAN NEVER BE GREATER THAN 2400.
	JRST ITILF
;MAKE SURE MINUTES PART OK (THIS ALWAYS SUCCEEDS IF ITS
;JUST HOURS)
	IDIVI B,^D100
	CAIL C,^D60
	JRST ITILF
;DON'T CHECK HOURS PART YET - ITS MAX VALUE DEPENDS ON
;MANY THINGS INCLUDING FOLLOWING INPUT, AND THIS FIELD
;(ONLY) CAN BE CHECKED AFTER CASES CONVERGE AND VALUES ARE
;COMBINED.
	POP P,C			;FIRST VALUE IN C
	CAIE G,":"		;COLON AFTER NUMBER?
	JRST ITN4		;NO, ONLY ONE NUMBER IN INPUT.

;COLON SEEN IN TIME, THERE WILL BE AT LEAST TWO NUMBERS

	TLNE F,B7		;SECONDS ILLEGAL?
	TLNN F,B9		;COLON ILLEGAL BETWEEN HRS AND MINS ALSO?
	JRST .+2
	JRST ITILF		;BOTH TRUE, NO COLONS ALLOWED
	CALL TNIN		;PASS SPACES, READ NUMBER <60.
	MOVE D,B		;VALUE OF SECOND NUMBER IN D
	CAIE G,":"
	JRST ITN5		;TIME CONSISTS OF TWO NUMBERS

;SECOND COLON SEEN, THERE WILL BE THREE NUMBERS

	TLNN F,B7		;SECONDS ILLEGAL?
	TLNE F,B9		;COLON ALLOWED BETWEEN HOURS AND MINS?
	JRST ITILF		;TWO COLONS NOT ALLOWED
	CALL TNIN		;PASS SPACES, READ THIRD NUMBER
	MOVE E,B		;THIRD VALUE IN E
	JRST ITN7		;GO COMBINE VALUES

;ONLY ONE NUMBER IN TIME

ITN4:	TLNN F,B10		;COLON MANDATORY BETWEEN HOURS AND MINS?
	TLNE F,B8		;SEcONDS MANDATORY?
	JRST ITILF
	JRST ITN5B		;GO SEPERATE HOURS AND MINUTES. 
				;SECONDS ALREADY ZEROED.
;IDTNCS...
;TWO NUMBERS IN TIME

ITN5:	TLNE F,B8		;SECONDS REQUIRED?
	TLNN F,B10		;COLON REQUIRED BETWEEN HOURS AND MINUTES?
	JRST .+2
	JRST ITILF		;YES AND YES, TWO COLONS REQUIRED.
	TLNN F,B9		;COLON ILLEGAL?
	TLNE F,B8		;SECONDS REQUIRED?
	JRST ITN5A		;YES OR YES, TAKE IT AS HHMM:SS
	TLNN F,B7		;SECONDS ILLEGAL?
	TLNE F,B10+B12		;COLON REQ'D OR "TAKE AS HH:MM IF B7-10 OFF"?
	JRST ITN7		;YES, YES, OR YES, TAKE AS HH:MM
	TLNE F,B11		;"TAKE AS HHMM:SS IF B7-B10 OFF"?
	JRST ITN5A		;YES. THIS TEST MUST BE AFTER B7-10!

;B7-B12 ALL OFF, TAKE AS HH:MM IF POSSIBLE, ELSE HHMM:SS.
;WE MUST SEE WHETHER AM-PM IS PRESENT TO KNOW MAXIMUM
;HOUR VALUE IN ORDER TO DECIDE WHETHER WE CAN TAKE IT AS
;HH:MM.

	TLNE F,B14
	JRST ITN58		;24-HOUR TIME ILLEGAL, 12 HOURS.
	TLNE F,B15
	JRST ITN59		;AM-PM ILLEGAL, 24 HOURS.
	CAIG G,"Z"
	CAIGE G,"A"
	JRST ITN59		;NO LETTER, NO AM-PM.
ITN58:	CAILE C,^D12		;AM-PM WILL BE PRESENT, MAX TIME 12:59.
	JRST ITN5A		;HOURS TOO BIG, HHMM:SS.
;JRST ITN7		;HH:MM. FALLING THRU WILL GET TO ITN7.
ITN59:	CAIN C,^D24		;NO AM-PM, MAX TIME 24:00
	JUMPE D,ITN7		;HOURS=24, HH:MM IF MINS =0.
	CAIGE C,^D24
	JRST ITN7		;FIRST NUMBER SMALL ENOUGH FOR HH:MM.

;TWO NUMBERS IN TIME, TO BE TAKEN AS HHMM:SS

ITN5A:	MOVE E,D		;SECONDS
ITN5B:	IDIVI C,^D100		;SEPERATE HOURS AND MINUTES.

;COMBINE HOURS, MINUTES, SECONDS INTO C.

ITN7:	IMULI C,^D60
	ADD C,D
	IMULI C,^D60
	ADD C,E
	CAIL C,^D<24*3600>	;MAX VALUE IN ANY CASE
	JRST ITILF
	TLNE F,B14		;24-HOUR TIME DISALLOWED?
	JRST ITN8		;YES, AM-PM MANDATORY.
	TLNE F,B15		;AM-PM ALLOWED?
	JRST ITN9		;NO
	CAIG G,"Z"		;AM-PM OPTIONAL. LETTER NEXT?
	CAIGE G,"A"		;..
	JRST ITN9		;NO
;IDTNCS...
;INPUT AM-PM AND MAKE APPROPRIATE CHECKS AND ADJUSTMENTS TO YIELD
;24-HOUR TIME.
;THE TIMES PRECEDING AM-PM MUST BE BETWEEN 1:00:00 AND 12:59:59.

ITN8:	CAIG C,^D<<12*60+59>*60+59>
	CAIA C,^D3600		;NO, ALSO ALLOW 0:00:00 TO 0:59:59
	JRST ITILF
	CALL AMPM		;READ STRING, SEARCH TABLE, RETURN +1 - +4.
	JRST [	CAIL C,^D<12*3600> ;+1: AM
		SUBI C,^D<12*3600> ;12AM=MIDNITE, AFTER 12=MORNING
		JRST .+4]
	JRST [	CAIGE C,^D<12*3600> ;+2: PM
		ADDI C,^D<12*3600> ;BEFORE 12=AFTERNOON, 12PM=NOON
		JRST .+3]
	JRST [	CAIE C,^D<12*3600> ;+3: NOON
		JRST ITILF	;ONLY 12 NOON ALLOWED
		JRST .+2]
	JRST [	CAIE C,^D<12*3600> ;+4: MIDNITE
		JRST ITILF
		JRST .-2]	;GO ADD 12 HOURS
;ABOVE MANIPULATIONS CAN MAKE MIDNITE COME OUT 24:00:00
;AS OPPOSED TO 0:00:00.  THE FOLLOWING FIXES THAT,
;AND ALSO CHANGES 24:00:00 (WHICH IS OK TO INPUT WITHOUT
;AM-PM) TO 0.
ITN9:	HRR CC,C		;RETURN LOCAL TIME IN RH D.
	SETZ C,			;IF NO TIME ZONE, RETURN LH D ZERO
				;EXCEPT FOR LOCAL TIME ZONE (BELOW).
	TLNE F,B16		;TIME ZONE ALLOWED IN INPUT?
	JRST ITN10
	CAIE G,"-"		;"-" PRECEDES TIME ZONE
	JRST ITN10		;NO TIME ZONE
	CALL IDCHAR		;NEXT CHARACTER
	CAIG G,"Z"		;LETTER NEXT?
	CAIGE G,"A"		;..
	JRST ITN10		;NO, NO TIME ZONE (EXTRA CHAR READ)
	CALL ZONE		;INPUT STRING, SEARCH TIME ZONES TABLE, 
				;RETURN THE RIGHT THING IN C (INCL B2 ON).
				;(NOTE THAT "DAYL" OR "STD" CAN BE INPUT,
				;WHICH LEAVES B2 OFF.)
ITN10:	MOVE B,TIMZON		;LOCAL TIME ZONE
	TRNN C,B2		;UNLESS A TIME ZONE WAS INPUT,
	DPB B,[POINT 6,C,35]	;RETURN LOCAL TIME ZONE IN C B12-17
	HRL CC,C		;RETURN THIS STUFF IN LH D.
;IDTNCS...
;NOW DONE DECODING DATE AND TIME.
;CHECK TERMINATOR: IT SHOULD BE NON-ALPHANUMERIC

IDTNC8:	CAIG G,"Z"
	CAIGE G,"A"
	JRST [	CAIG G,"9"
		CAIGE G,"0"
		JRST .+2
		JRST .+1]
	JRST [	TLNN F,B6
		JRST ITILF
		JRST IDILF]

;GIVE GOOD RETURN

	TLNE F,B0		;ON TO SUPPRESS DATE INPUT
	JRST IDTN11		;DATE INPUT SUPPRESSED
	MOVE B,AA		;B/YEAR,,MONTH
	HLLZ C,BB		;C/DAY OF MONTH,,0
	MOVE D,CC		;FIRST ASSUME USER TYPED IN A TIME
	TXNE F,IT%NTI		;SKIP IF WE'RE RIGHT
	HRRZI D,1		;NO TIME INPUT, SO PICK ONE. AND CLEAR MEANINGLESS LH.
	IDCNV			;GET INTERNAL DATE AND TIME
	 RETBAD (,<MOVE B,A>)	;RETURN WITH ERROR (THIS CAN OCCUR WITH BAD DATE TO IDTIM ETC.)
	ODCNV			;THIS IS JUST TO GET DAY OF THE WEEK
	RETSKP

;HERE WHEN DATE INPUT SUPPRESSED--RETURN CURRENT DATE VALUES

IDTN11:	SETO B,			;-1=CURRENT DATE/TIME
	SETZ D,			;DEFAULT TIME ZONE HANDLING
	ODCNV			;GET TODAYS VALUE
	 ERJMP [MOVE  B,LSTERR	;SEE IF CLOCK NOT TURNED ON YET
		CAIE B,DATEX6	;CLOCK ON?
		RETBAD		;YES - FAIL
		SETOM B		;NO - RETURN -1 FOR DATE
		SETOM C
		JRST .+1]	;NOW  GIVE TIME IN SECONDS
	MOVE D,CC		;RETURN TIME INPUT, RESULTS IN PROPER ACS
	RETSKP			;SKIP RETURN


;ERROR RETURN STUFF

IDILF:	SKIPA B,[DILFX1]	;"ILLEGAL FORMAT FOR DATE"
ITILF:	MOVEI B,TILFX1		;"ILLEGAL FORMAT FOR TIME"

;COME HERE WITH ERROR CODE IN B

	MOVE P,DD		;RESTORE P (CAN GET HERE FROM SUBRS WITH AN
				;INDEFINITE NUMBER OF EXTRANEOUS WORDS IN PD).
	MOVEM B,LSTERR		;SAVE ERR CODE IN PSB FOR "GETER", ETC
	SE1CAL			;ENTER SECTION 1 FOR RETURN
	RET			;RETURN +1 WITH ERROR CODE IN ACTUAL B
;SUBROUTINES FOR IDTNCS

;INPUT ALPHANUMERIC MONTH
;ACCEPTS ANY "UNIQUE SUBSTRING" OF A MONTH NAME.
;IGNORES PRECEDING SPACES AND (ON R2) PASSES FOLLOWING SEPERATING CHARS.
;R1: NEXT NON-SPACE CHAR NOT A LETTER.
;R2: SUCCESS, MONTH # IN RH AA.
;CLOBBERSS B,C,D,E.

MONTH:	CALL GNSC		;GET NON-SPACE CHARACTER
	CAIG G,"Z"
	CAIGE G,"A"
	RET			;NO LETTER: R1
	CALL IDSTR		;READ STRING. BUFFERS IT IN PD. PUTS OLD
				;P VALUE IN E.
	XMOVEI C,MONTHS		;TABLE ADDRESS
	CALL FSYM		;SEARCH TABLE
	 JRST IDILF		;NOT FOUND, ILLEGAL DATE FORMAT
	HRR AA,C		;RETURN MONTH
	MOVE P,E		;DEALLOCATE STRING SPACE IN PD
	AOS (P)			;SKIP
	JRST IDSEP		;RETURN VIA SUBR TO PASS SEPERATING CHARS

;MACRO FOR TABLES OF MONTHS, AM-PM'S, TIME ZONES
	DEFINE TM (TEXT,VALUE)
	<XWD VALUE,[ASCIZ /TEXT/]>

;MONTH TEXTS TABLE, IN FSYSM FORMAT

MONTHS:	^D12			;WORD 0 OF TABLES IS NUMBER OF ENTRIES
	TM APRIL,3
	TM AUGUST,7
	TM DECEMBER,^D11
	TM FEBRUARY,1
	TM JANUARY,0
	TM JULY,6
	TM JUNE,5
	TM MARCH,2
	TM MAY,4
	TM NOVEMBER,^D10
	TM OCTOBER,^D9
	TM SEPTEMBER,^D8
;IDTNCS SUBROUTINES...

;SUBROUTINE TO INPUT YEAR
;RETURNS YEAR IN LH AA

YEAR:	CALL IDNIN		;INPUT NUMBER
	 JRST IDILF		;NONE, ILLEGAL DATE FORMAT ERROR
	CAIGE B,^D100
	ADDI B,^D1900
	CAIL B,^D1858
	CAILE B,^D2576
	 JRST IDILF		;OUT OF RANGE, "ILLEGAL FORMAT"
	HRL AA,B
	RET


;AM-PM LOOKUP ROUTINE. FIRST CHARACTER MUST BE IN G.
;ACCEPTS ONE OF MORE LETTERS OF --     AND RETURNS + --
;	AM		1
;	PM		2
;	NOON		3
;	MIDNIGHT	4
;CLOBBERS B,D,E
;ONLY CALLED IN ONE PLACE; CODED AS A SUBR TO FACILITATE CHANGE SUCH
;AS SUBSTITUTION OF A SIMPLER SYMBOL TABLE SEARCH.

AMPM:	PUSH P,C
	CALL IDSTR
	XMOVEI C,AMPMS
	CALL FSYM
	 JRST ITILF
	MOVE P,E
	ADDM C,-1(P)		;INCREMENT RETURN BY VALUE FROM TABLE
	POP P,C
	RET

AMPMS:	4
	TM AM,0
	TM MIDNIGHT,3
	TM NOON,2
	TM PM,1
;IDTNCS SUBROUTINES...

;TIME ZONE LOOKUP SUBROUTINE. FIRST CHAR MUST BE IN G.
;ACCEPTS ANY UNIQUE SUBSTRING OF ANY OF THE US STANDARD OR
;DAYLIGHT TIME ZONE ABBREVIATIONS, ALSO "STANDARD" AND "DAYLIGHT".
;RETURNS IN RH C WHAT IDTNC SHOULD RETURN IN LH D,
;EXCEPT THAT LOCAL TIME ZONE ISN'T FILLED IN FOR "DAY" OR "STD".
;CLOBBERS B,D,E.
;LIKE "AMPM", THIS SUBR IS ONLY USED IN ONE PLACE.

ZONE:	CALL IDSTR
	XMOVEI C,ZONES
	CALL FSYM
	 JRST ITILF
	MOVE P,E
	RET

ZONES:	EXP ZONSIZ
	TM ADT,B0+B1+B2+4	;ATLANTIC DAYLIGHT TIME
	TM AST,B0+B2+4		;ATLANTIC STANDARD TIME
	TM BDT,B0+B1+B2+^D11	;BERING DAYLIGHT TIME
	TM BST,B0+B2+^D11	;BERING STANDARD TIME
	TM CDT,B0+B1+B2+6	;CENTRAL DAYLIGHT TIME
	TM CST,B0+B2+6		;CENTRAL STANDARD TIME
	TM DAYLIGHT,B0+B1	;LOCAL DAYLIGHT TIME
	TM EDT,B0+B1+B2+5	;EASTERN DAYLIGHT TIME
	TM EST,B0+B2+5		;EASTERN STANDARD TIME
	TM GDT,B0+B1+B2+0	;GREENWICH DAYLIGHT TIME
	TM GMT,B0+B2+0		;GREENWICH MEAN TIME
	TM GST,B0+B2+0		;GREENWICH STANDARD TIME
	TM HDT,B0+B1+B2+^D10	;ALASKA-HAWAII DAYLIGHT TIME
	TM HST,B0+B2+^D10	;ALASKA-HAWAII STANDARD TIME
	TM MDT,B0+B1+B2+7	;MOUNTAIN DAYLIGHT TIME
	TM MST,B0+B2+7		;MOUNTAIN STANDARD TIME
	TM PDT,B0+B1+B2+^D8	;PACIFIC DAYLIGHT TIME
	TM PST,B0+B2+^D8	;PACIFIC STANDARD TIME
	TM ST,B0		;"ST" OK FOR "STANDARD"
	TM STANDARD,B0
	TM STD,B0		;"STD" OK FOR "STANDARD"
	TM YDT,B0+B1+B2+^D9	;YUKON DAYLIGHT TIME
	TM YST,B0+B2+^D9	;YUKON STANDARD TIME

ZONSIZ==.-ZONES

;IDTNCS SUBROUTINES...

;SUBROUTINE FOR "MONTH", "AMPM", AND "ZONE" TO READ A STRING OF LETTERS.
;FIRST CHARACTER MUST BE IN G. STORES IN ASCIZ FORM IN PUSHDOWN,
;RETURNING PREVIOUS P VALUE IN E AND STRING POINTER IN B.
;CLOBBERS C,D.

IDSTR:	MOVE E,P		;SAVE PUSHDOWN LEVEL
	SUB E,BHC+1		;...BEFORE THIS ROUTINE WAS CALLED
	HRRI C,1(P)
	HRLI C,<POINT 7,0,-1>B53 ;FORM BYTE PTR INTO PUSHDOWN
	MOVEI D,^D14		;MAX LENGTH 3 WORDS
	PUSH P,[0]		;ALLOCATE 3 WORD OF BUFFER SPACE, ALSO
	PUSH P,[0]		;ZEROS REST OF LAST WORD
	PUSH P,[0]		;(NEEDED FOR SEARCH ROUTINE "FSYM")
IDSTR2:	IDPB G,C		;STORE CHARACTER
	CALL IDCHAR
	CAIG G,"Z"
	CAIGE G,"A"
	JRST IDSTR9		;NON-LETTER ENDS STRING
	SOJG D,IDSTR2		;GO STORE CHARACTER
;STOP ANYWAY AT 14 CHARS. THE APPROPRIATE "ILLEGAL FORMAT"
;ERROR WILL HAPPEN IN CALLING ROUTINE BECUASE NOTHING
;14 CHARS LONG IS IN TABLES.
IDSTR9:	HRRI B,2(E)		;RETURN BYTE PTR TO STRING IN B
	HRLI B,<POINT 7,0,-1>B53
	MOVE C,1(E)		;FETCH RETURN ADDR FROM PD
	JRST (C)		;RETURN
;IDTNCS SUBROUTINES...

;TABLE SEARCH FOR "MONTH", "AMPM", "ZONE"
;TAKES IN B: POINTER TO LEFT ADJUSTED ASCIZ STRING
;	  C: POINTER TO TABLE OF THE FORM:
;		WORD 0: N=NUMBER OF ENTRIES
;		WORDS 1-N: LH: V=VALUE
;			   RH: POINTER TO ASCIZ STRING
;		ENTRIES MUST BE IN ALPHABETICAL ORDER
;RETURNS +1: NO MATCH OR AMBIGUOUS
;	 +2: UNIQUE SUBSET OR EXACT MATCH, VALUE "V" IN RH C.
;AC USE
;   A	POINTS AT LAST ENTRY IN TABLE
;   B   POINTER WHICH IS INDEXED THRU INPUT TEXT
;   C   POINTER INTO TABLE
;   D   WORD OF INPUT TEXT
;   E   POINTER WHICH IS INDEXED THROUGH THE TEXT OF A TABLE ENTRY
;   F   WORD OF TEXT FROM TABLE ENTRY
;   G   "DELTA" - THE BINARY SEARCH INCREMENT

 IFN E-D-1,<PRINTX FSYM WON'T WORK CAUSE E IS NOT D+1
>
;IDTNCS SUBROUTINE FSYM...

FSYM:	PUSH P,A		;SAVE AC'S
	PUSH P,B
	PUSH P,C
	PUSH P,D
	PUSH P,E
	PUSH P,F
	PUSH P,G
	MOVE A,C		;TABLE LOCATION

;INIT DELTA TO HIGHEST POWER OF 2 IN TABLE LENGTH

	MOVE D,(A)		;TABLE LENGTH
	JFFO D,.+2
	JRST NOMAT		;0 LENGTH: NO MATCH
	MOVEI G,1
	MOVN E,E
	LSH G,43(E)		;SHIFT BY 35 - # OF 0 BITS TO GET POWER

	MOVEI C,(A)		;INIT POINTER THAT RUNS OVER TABLE
	ADD A,(A)		;LOCATION OF LAST USED ENTRY IN TABLE
;IDTNCS SUBROUTINE FSYM...

; BINARY SEARCH. STOPS AT = ENTRY OR SMALLEST > ENTRY.

FSRC1:	ADDI C,(G)		;ADD DELTA TO TABLE POINTER
FSRC1A:	LSH G,-1		;HALVE DELTA FOR NEXT TIME AROUND
	CAILE C,(A)
	JRST FSRC4		;POINTS BEYOND END OF TABLE, GO BACK UP.

;COMPARE THE INPUT TEXT TO A TEXT IN THE TABLE

	MOVE B,-5(P)		;GET VALUE THAT CAME IN B AS PTR TO INPUT TEXT
	HRRZ E,(C)		;POINTER INTO TABLE TEXT FROM TABLE WORD
FSRC2:	MOVE D,(B)		;GET AN INPUT WORD
	LSH D,-1		;POSITION SO DATA ISN'T IN SIGN BIT
	MOVEI B,1(B)		;INDEX INPUT POINTER
	MOVE F,(E)		;GET A WORD OF TABLE TEXT
	LSH F,-1
	CAMGE F,D
	JRST FSRC3		;TABLE ENTRY LESS THAN INPUT
	CAME F,D
	JRST FSRC4		;TABLE ENTRY GREATER THAN INPUT 
	TRNE D,177		;THESE WORDS EQUAL, AT END OF INPUT?
	AOJA E,FSRC2		;NO, INDEX TABLE TEXT PTR, CONTINUE COMPARE.

;MATCH FOUND.
;CODE FOR EXITS, SEARCH STUFF CONTINUES AFTER THIS.

UPAR:	AOS -7(P)
	HLRZ D,(C)		;VALUE FIELD FROM TABLE ENTRY WHICH MATCHED
	MOVEM D,-4(P)		;RETURN SAME IN C
APAR:
NOMAT:	POP P,G			;RESTORE AC'S
	POP P,F
	POP P,E
	POP P,D
	POP P,C
	POP P,B
	POP P,A
	RET			;RETURN

;THE TEXT OF THIS TABLE ENTRY IS LESS THAN INPUT STRING

FSRC3:	JUMPN G,FSRC1		;DELTA><0, GO MOVE DOWN AND CONTINUE SEARCH
	AOJA C,NEM1		;DONE SEARCH. NEXT ENTRY IN TABLE IS THE
;SMALLEST LARGER ENTRY. IF THERE IS NO NEXT ENTRY, THEN
;THERE IS NO MATCH. "SBST" SUBR IS CODED TO HANDLE THIS CASE.

;THIS TABLE ENTRY GREATER THAN INPUT, OR POINTER IS OF END OF TABLE

FSRC4:	SUBI C,(G)		;MOVE UP IN TABLE
	JUMPN G,FSRC1A		;UNLESS DELTA=0, CONTINUE SEARCH.
;IDTNCS SUBROUTINE FSYM...

;WE GET TO "NEM1" WHEN THE SEARCH COMPLETES WITHOUT FINDING AN EXACT
;MATCH.  C POINTS TO SMALLEST TABLE ENTRY GREATER THAN INPUT.
;THIS ENTRY MAY OR MAY NOT BE A SUBSET MATCH; IF IT IS, THEN IT IS 
;AMBIGUOUS IF AND ONLY IF NEXT ENTRY IS ALSO A SUBSET MATCH.
;NOTE ALSO THAT WE CAN TEST NEXT ENTRY FIRST, AND IF IT IS SUBSET,
;THEN WE KNOW INPUT IS AMBIGUOUS WITHOUT TESTING THIS ENTRY.

;TEST NEXT ENTRY

NEM1:	ADDI C,1		;POINT C AT NEXT ENTRY
	CALL SBST		;SUBSET TEST SUBR COMPARES ENTRY C TO INPUT
	SOJA C,NEM2		;R1: NOT A SUBSET (INCLUDES NO NEXT ENTRY)
	SOJA C,APAR		;R2: IS A SUBSET, SO INPUT IS AMBIG. GIVE R2.

;NOT AMBIGUOUS, SO TEST THIS ENTRY

NEM2:	CALL SBST
	JRST NOMAT		;INPUT NOT SUBSET THIS ENTRY, NO MATCH
	JRST UPAR
;IDTNCS SUBROUTINE FSYM...

;SUBSET TEST SUBROUTINE FOR "FSYM".
;COMPARES INPUT STRING AND STRING FOR TABLE ENTRY C POINTS TO,
; SKIPS IF FORMER IS INITIAL SUBSTRING OF LATTER.
;ON R2, RETURNS IN E A BYTE POINTER TO REST OF TABLE ENTRY STRING
;MUST BE CALLED ONLY WHEN INPUT STRING IS LESS THAN TABLE STRING
;SEE "FSYM"'S COMMENTS ON AC USE. CLOBBERS B,D,E,F,G.

SBST:	CAILE C,(A)		;C BEYOND END OF TABLE?
	RET			;YES, NO ENTRY, INPUT ISN'T SUBSET, RETURN.

;FIND FIRST WORD OF STRINGS IN WHICH THEY DIFFER

	MOVE B,-6(P)		;POINTER TO INPUT TEXT
	HRRZ E,(C)		;POINTER TO TABLE ENTRY'S TEXT
SBST1:	MOVE D,(B)		;WORD OF INPUT
	LSH D,-1		;POSITION FOR COMPARE
	MOVEI B,1(B)		;INDEX INPUT POINTER
	MOVE F,(E)		;WORD OF TABLE ENTRY
	LSH F,-1		;POSITION
	CAMG F,D
	AOJA E,SBST1		;IF ITS = IT MUST NOT BE END.
	TRNE D,177		;IS DIFFERENCE IN LAST WORD OF INPUT?
	RET			;NO, INPUT CAN'T BE SUBSTRING OF TABLE ENTRY.

;MASK OFF TABLE TEXT TO LENGTH OF INPUT

	HRLZI G,-4
	TDNE D,TBLBTS(G)	;LOOP TO SEE HOW MANY BYTEST OF D ARE 0
	AOBJN G,.-1
	ANDCM F,TBLBTS(G)		;THIS CLEARS F WHERE THERE ARE BITS IN TABLE

;CONVERT WORD PTR IN E TO BYTE POINTER AS REQUIRED ON R2.

	HLL E,	[POINT 7,0,-1
		POINT 7,0,6
		POINT 7,0,13
		POINT 7,0,20
		POINT 7,0,27 ] (G)

;NOW IF MASKED PART OF TABLE WORD = INPUT WORD, INPUT IS SUBSET.

	CAMN F,D
	RETSKP
	RET

TBLBTS:-1
	1777777777
	7777777
	37777
	177
;IDTNCS SUBROUTINES...

;NUMBER INPUT CONVERSION: CAN'T USE SYSTEM'S NIN  BECAUSE STRING
;POINTER MUST ADDRESS CALLER'S, NOT CURRENT PC'S, ADDRESS SPACE,
; AND IN ANY CASE NOT UNTIL BKJFN
; WORKS FOR ALL DEVICES OR ANOTHER MEANS OF RETURNING TERMINATOR
; IS ESTABLISHED.
;R1: NO DIGIT OR OVERFLOW (18 BITS)
;R2: VALUE IN B

IDNIN:	CALL GNSC		;GET NON-SPACE CHARACTER
	CAIG G,"9"
	CAIGE G,"0"
	RET
	MOVEI B,-60(G)
NIN1:	CALL IDCHAR
	CAIG G,"9"
	CAIGE G,"0"
	RETSKP
	IMULI B,^D10
	ADDI B,-60(G)
	TLNN B,-1
	JRST NIN1
	RET			;OVERFLOW


;NIN FOR MONTH OR DAY OF MONTH
;ERROR IF NOT IN RANGE 1 TO 31.
;RETURNS VALUE -1 IN B.

DNIN:	CALL IDNIN
	 JRST IDILF
	SOJL B,IDILF
	CAIL B,^D31
	JRST IDILF
	RET


;NIN FOR MINUTES OR SECONDS: ERROR IF >= 60

TNIN:	CALL IDCHAR		;PASS PRECEDING SEPARATOR
	CALL IDNIN
	 JRST ITILF
	CAIL B,^D60
	JRST ITILF
	RET
;IDTNCS SUBROUTINES...

;SEPERATOR BETWEEN DATE FIELDS:
;ANY NUMBER OF SPACES, DASH OR SLASH, ANY NUMBER OF SPACES.

IDSEP:	CALL GNSC
	CAIE G,"-"
	CAIN G,"/"
	CALL IDCHAR
	JRST GNSC


;GET NON-SPACE CHARACTER INTO G

GNSC:	CAIE G," "
	RET
	CALL IDCHAR
	JRST GNSC


;GET NEXT INPUT CHARACTER INTO G

IDCHAR:	PUSH P,B
	CALL BIN1		;INPUT TO B FROM SOURCE IN CALLER'S A.
	 MOVEI B,0		;EOF SEEN
	CAIL B,141
	CAILE B,172
	JRST .+2
	SUBI B,40		;CONVERT LOWER CASE TO UPPER
	MOVE G,B
	POP P,B
	RET

;ODCNV

; OUTPUT DATE AND TIME CONVERT
; BREAKS DOWN INTERNAL DATE AND TIME TO LOCAL WEEKDAY, DAY, MONTH,
;	AND YEAR, BUT DOES NOT CONVERT TO TEXT.

;TAKES: 2: LEFT HALF: INTERNAL DATE
;	   RIGHT HALF: INTERNAL TIME
;	   OR ENTIRE WORD -1 FOR CURRENT DATE AND TIME
;	4: (0 FOR NORMAL CASE)
;	   B0: OFF, USE DAYLIGHT SAVINGS OR NOT AS APPROPRIATE FOR
;		    GIVEN DATE
;	       ON, USE DAYLIGHT SAVINGS IF AND ONLY IF B1 IS ON.
;	   B2: OFF, USE LOCAL TIME ZONE
;	       ON, USE TIME ZONE IN B12-B17

;RETURNS +1: 2: LEFT HALF: REAL YEAR (IE SINCE THE YEAR 0)
;		RIGHT HALF: MONTH (0=JANUARY)
;	     3: LEFT HALF: DAY OF MONTH (FIRST DAY = 0)
;		RIGHT HALF: DAY OF WEEK (MONDAY = 0)
;	     4: B0: ON
;		B1: ON IF DAYLIGHT SAVING TIME WAS USED
;		B2: ON
;		B12-17: TIME ZONE USED: NUMBER OF HOURS WEST OF
;		        GREENWICH, EG EST = 5.
;		RH: LOCAL TIME IN SECONDS SINCE MIDNITE

;ODCNV ERROR MNEMONICS (TRAP)
;DATEX6: SYSTEM HAS NO DATE AND TIME (AND -1 WAS GIVEN)
;TIMEX1: ILLEGAL TIME (GREATER THAN 24 HOURS)
;ZONEX1: ILLEGAL TIME ZONE

;INTERNAL AC USE
;	B: YEAR,,MONTH
;	C: SYSTEM INTERNAL TIME, THEN LOCAL TIME
;	D: DAY OF YEAR
;	AA: TIME STUFF FROM, THEN TO, D.
;	BB: SYSTEM INTERNAL, LATER LOCAL, DATE (MUST BE A FULL WORD
;	    QUANTITY BECAUSE TIME ZONE CAN TAKE IT OVER 18 BITS.)
;ODCNV JSYS

.ODCNV:	MCENT
	MOVE AA,D		;TIME ZONE AND DAYLIGHT GARBAGE

;GET INTERNAL (GREENWICH) DATE & TIME TO CONVERT INTO BB AND C

	CAME B,[-1]
	 JRST ODC2		;DATE & TIME GIVEN
	PUSH P,A		;SAVE DESTINATION
	CALL LGTAD		;GET SYSTEM TIME AND DATE
	CAMN A,[-1]
	JRST [	POP P,A
		MOVEI B,DATEX6	;SYSTEM HAS NO DATE AND TIME
		JRST ODCER]
	MOVE B,A
	POP P,A
ODC2:	HRRZ C,B		;TIME IN C
	MULI C,^D<24*3600>	;CONVERT TO SECONDS/DAY
	DIV C,[1B17]		;SHIFT BINARY POINT
	CAIL D,400000		;ROUND
	AOS C
	HLRZ BB,B		;DATE IN BB

;CHECK FOR REASONABLE ARGUMENT: ANY 18 BITS OK FOR DATE;
; TIME MUST BE .L. 2400.

	CAIL C,^D<24*3600>
	JRST [	AOS BB		;OVERFLOWED INTO NEXT DAY
		SETZ C,		;MAKE IT BE SECOND # 0
		HRLZ B,BB	;OF THE NEXT DAY
		JRST .+1]

;CONVERT TIME TO LOCAL STD AND ADJUST INTERNAL FORMAT DATE TO LOCAL.
;THIS MUST BE DONE FIRST BECAUSE IT CAN CHANGE YEAR

	CALL CNVZON		;GET TIME ZONE AS SECONDS EARLIER THAN GMT
	 JRST ODCER		;BAD ZONE, GIVE ERR RET
	SUB C,E			;ADJUST TIME FOR TIME ZONE
	CALL FIXDT		;IF TIME NOW OUT OF RANGE 0 TO 23:59:59,
				;ADD OR SUBTRACT 24 HOURS AND ADJUST DATE
				;CORRESPONDINGLY.
;ODCNV...
;CONVERT SYSTEM DATE (DAY 1=18 NOV 1858) IN LH C
; TO YEAR IN LH A AND DAY OF YEAR IN D.
;ALLOW FOR LEAP YEARS, WHICH RUN IN CYCLES OF:
; 4 YEARS, EG 1961-64, LAST YEAR NORMALLY LEAP.
; "CENTURIES", EG 1801-1900, LAST YEAR NORMALLY NON-LEAP.
; "QUADRACENTURIES", EG 1501-1900, FIRST "CENTURY" THEREOF
;     1 DAY LONGER THAN OTHERS CUASE ITS LAST YEAR IS LEAP.
;NOTE: DATE IS TREATED AS 18-BIT MAGNITUDE --
; DATES BEFORE 18 NOV 1858 CANNOT BE REPRESENTED.

	MOVE D,BB		;INTERNAL DATE

;SCALE SO DAY 0 IS 1/1/1501,
;THE BEGINNING OF A QUADRACENTURY.
;DERIVATION OF NUMBER ADDED:
; 365*358	YEARS 1501 TO 1859
; 89-2		LEAP YEARS IN THAT INTERVAL
; -12-31-1	DAYS 1 JAN 1859 TO 18 NOV 1858
; -1	BASE DAY IS 0 NOT 1

	ADDI D,^D<365*358+89-2-12-31-1-1>

;DO THREE DIVIDES, 1 FOR EACH CYCLE,
;ACCUMULATING # YEARS IN D.

	IDIVI D,^D<400*365+97>	;# DAYS / QUADRACENTURY
	IMULI D,^D400		;CONVERT # QUADRACENTURIES TO YEARS
;DAY OF QUADRACENTURY IS IN E. SCALE TO QUARTER-DAYS AND
;DIVIDE BY N+1/4 DAYS SO THAT FIRST CENTURY OF QUADRACENTURY
;GETS EXTRA DAY.
	LSH E,2
	IDIVI E,<^D<100*365+24>>B33+1 ;# QUARTER-DAYS / CENTURY
	IMULI E,^D100		;CONVERT # CENTURIES TO YEARS
	ADD D,E			;ADD TO # YEARS FOR QUADRACENTURIES
	LSH F,-2		;SCALE BACK TO DAYS
;DAY OF CENTURY IS IN F
	IDIVI F,^D365*4+1	;# DAYS IN A 4-YEAR CYCLE
	LSH F,2			;CONVERT # 4-YEAR CYCLES TO YEARS
	ADD D,F			;ADD TO YEARS SO FAR
	MOVE F,G		;DAY WITHIN 4-YEAR CYCLE
	IDIVI F,^D365		;DIVIDE BY NUMBER OF DAYS IN REGULAR YEAR
	CAIE F,4		;IF WE GOT 5TH YEAR, IT IS REALLY...
	JRST .+3
	MOVEI G,^D365		;366TH DAY OF...
	SUBI F,1		;4TH (LEAP) YEAR OF 4-YEAR CYCLE.
	ADD D,F			;ADD YEAR OF 4-YEAR CYCLE TO YEARS SO FAR
;EXCEPTION FOR THE LAST YEAR OF MOST CENTURIES IS HANDLED BY
;THE FACT THAT DAY 365 OF YEAR 99 CAN GET HERE ONLY FOR
;CENTURY 0 OF A QUADRACENTURY.  (OTHERWISE ABOVE DIVIDE
;YIELDS DAY 0 OF NEXT CENTURY.)

;NOW HAVE CORRECT YEAR. SCALE IT TO YEARS SINCE 0AD AND RETURN IT.

	ADDI D,^D1501
	HRL B,D			;RETURN YEAR IN LH B
	MOVE D,G		;DAY OF YEAR TO D
;ODCNV...
;FOR NON-LEAP YEARS INCREMENT DAY OF YEAR IF AFTER FEB 28

	TLNN AA,B3		;SKIP IF JULIAN FORMAT
	CALL NLEAP		;SKIP IF NOT LEAP YEAR (USES LH B)
	 JRST ODLEAP
	CAIL D,^D<31+28>
	ADDI D,1

;ADJUST FOR DAYLIGHT SAVING

ODLEAP:	CALL ODAYL		;SKIP IF DAYL SAVINGS APPLIES (USES C,D,AA,BB)
	JRST ODCSTD		;NOT DAYLIGHT SAVINGS
	ADDI C,^D3600		;ADD AN HOUR
	CAIGE C,^D<24*3600>;DID IT RUN ACCROSS MIDNITE?
	JRST ODC7
	ADDI D,1		;NEXT DAY OF YEAR
	ADDI BB,1		;NEXT LOCAL DATE (USED FOR DAY OF WEEK)
	SUBI C,^D<24*3600>	;24 HOURS EARLIER
	TLNN AA,B3		;SKIP IF JULIAN FORMAT
	CALL NLEAP		;LEAP YEAR?
	 JRST ODC8		;YES
	CAIN D,^D<31+28>	;NO, DID DST MAKE IT FEB 29?
	ADDI D,1		;YES, BUMP DAY
ODC8:	CAIL D,^D366		;DID IT RUN OVER END OF YEAR?
	JRST [	SETZ D,		;YES, SOME NUT IS LOOKING FOR A BUG
				;OR IS IN SOUTHERN HEMISPHERE.
		ADD B,[1B17]	;NEXT YEAR
		JRST .+1]
ODC7:
ODCSTD:

;NOW DONE WITH TIME AND YEAR. YEAR ALREADY IN LH B.

	HRR AA,C		;SAVE TIME FOR RETURN IN C.

;MONTH AND DAY OF MONTH

	TLNE AA,B3		;ALL DONE IF JULIAN FORMAT
	JRST [	HRRI B,1(D)	;MAKE 1 := 1 JAN
		HRLI C,0	;CLEAR DAY OF MONTH
		JRST ODCJ]	;STILL GET DAY OF WEEK
	SETZ A,			;GENERATE MONTH NUMBER IN RH A
	CAML D,DAYS+1(A)	;FIND MONTH WITH MORE DAYS DAYS BEFORE IT
	AOJA A,.-1
	SUB D,DAYS(A)		;SUBTRACT DAYS IN PRECEDING MONTH
	HRR B,A
	HRL C,D			;RETURN DAY OF MONTH

;DAY OF WEEK

ODCJ:	MOVE E,BB		;LOCAL DATE IN SYSTEM FORMAT
	ADDI E,DWFUDG
	IDIVI E,7
	HRR C,F			;RETURN IT

;EXIT

	UMOVEM B,B
	UMOVEM C,C
	UMOVEM AA,D
	MRETNG

;ERROR RETURN, ERROR CODE MUST BE IN B

ODCER:	MOVEM B,LSTERR		;SAVE ERROR CODE IN PSB
	JRST ITRAP		;GIVE ILLEGAL INSTRUCTION PSI
;IDCNV

; INPUT DATE CONVERT
; TAKES LOCAL YEAR, MONTH, DAY, AND TIME (AS NUMBERS) AND
; 	GENERATES INTERNAL DATE AND TIME

;THIS JSYS IS A SUBSET OF IDTIM AND WILL ONLY BE USED BY THOSE WHO
;WISH TO MANIPULATE HOURS, DAY OF WEEK, ETC AS SEPERATE NUMBERS,
;OR WHO WISH TO INPUT DATE AND/OR TIME IN A FORMAT NOT ACCEPTED BY
;IDTIM, THEN CONVERT TO STANDARD INTERNAL FORMAT.

;TAKES: 2: LH: REAL YEAR
;	   RH: MONTH (JANUARY = 0)
;	3: LH: DAY OF MONTH
;	4: LH (0 FOR NORMAL CASE):
;	      B0: OFF, USE DAYLIGHT SAVING IF APPROPRIATE FOR GIVEN DATE
;	          ON, SEE B1
;	      B1: ON TO USE DAYLIGHT SAVING IF B0 ON
;	      B2: OFF, USE LOCAL TIME ZONE
;	          ON, USE TIME ZONE IN B12-17
;	      B12-B17: IF B2 ON, TIME ZONE TO USE, AS NUMBER OF HOURS
;		       WEST OF GREENWICH.*
;	   RH: LOCAL TIME IN SECONDS SINCE MIDNITE

;RETURNS +1: FAILURE, ERROR NUMBER IN A (SEE BELOW)
;	 +2: SUCCESS:
;	     2: LH: INTERNAL DATE (DAYS SINCE 18 NOV 1858, GREENWICH)
;		RH: INTERNAL TIME (SECONDS  SINCE MIDNITE AT GREENWICH)
;	     3: B0: ON
;		B1: ON IF DAYLIGHT SAVINGS WAS APPLIED
;		B2: ON
;		B12-17: TIME ZONE USED

;IDCNV ERROR MNEMONICS:
;TIMEX1
;DATEX1: ILLEGAL YEAR (OUT OF RANGE 1858 TO 2576)
;DATEX2: MONTH TOO LARGE
;DATEX3: DAY OF MONTH TOO LARGE
;DATEX5: ILLEGAL DATE (OUT OF RANGE 17 NOV 1858 TO 7 AUG 2576 GMT)
;ZONEX1: ILLEGAL TIME ZONE

;INTERNAL AC USE
;	B-C: ARGUMENTS; C: LOCAL TIME.
;	D: DAY OF YEAR
;	AA: ARGUMENT FROM D, THEN RESULT TO, D
;	BB: LOCAL DATE

;* TIME ZONE IS NUMBER OF HOURS WEST OF GREENWICH AND CAN RANGE FROM
;  -12 TO 12 (DECIMAL).  THE ZONES -12 AND +12 REPRESENT THE SAME
;  TIME DIFFERENCE BUT ON OPPOSITE SIDES OF THE INTERNATIONAL DATE
;  LINE.
;IDCNV

.IDCNV:	MCENT
	MOVE AA,D		;TIME ETC FROM D IN AA THRUOUT IDCNV

;CHECK ARGUMENTS, GET DAY OF YEAR IN D

	CALL CKYMDT		;CHECK YEAR, MONTH, DAY OF MONTH, TIME, AND
				;COMPUTE DAY OF YEAR WHILE SO DOING.
				;USES B,C,AA.
	 JRST IDCE		;BAD ARG, ERROR CODE IN B.

;CONVERT YEAR TO DAYS SINCE 1/1/1601 IN BB

	HLRZ BB,B		;YEAR
	CAIG BB,^D99
	ADDI BB,^D1900
	SUBI BB,^D1601
	MOVE F,BB
	IMULI BB,<^D365>B33+1	;365  1/4  DAYS PER YEAR
	LSH BB,-2
	IDIVI F,^D100
	SUB BB,F		;MINUS ONE DAY PER CENTURY
	LSH F,-2
	ADD BB,F		;BUT ADD BACK ONE DAY PER 4 CENTURIES

;COMBINE DATE, SCALE TO DAYS SINCE 11/17/1858

	ADD BB,D		;ADD DAY IN YEAR TO DAYS IN PRECEDING YEARS
	SUBI BB,^D<365*258+64-2-12-31-1-1>
				;SCALE SO DAY 1 IS 18 NOV 1858
				;THERE'S AN EXPLAINATION OF NUMBER ADDED
				;IN ODCNV

;FOR DATES AFTER FEB 28 IN NON-LEAP YEARS REMOVE THE DAY ALLOWED
;IN DATE FOR FEB 29.

	TLNE AA,B3		;USER GAVE JULIAN?
	JRST IDC6		;YES - SKIP THIS
	CAIL D,^D31+^D28	;BEFORE FEB 29?
	CALL NLEAP		;LEAP YEAR?
	 JRST IDC6		;YES OR YES
	CAIN D,^D31+^D28	;FEB 29?
	JRST [	MOVEI B,DATEX3	;YES, "ILLEGAL DAY OF MONTH"
		JRST IDCE]
	SUBI BB,1		;NOT LEAP YEAR, REMOVE FEB 29
;THE DAY FOR 2/29 IS INTENTIONALLY LEFT IN THE QUANTITY IN D,
;BECAUSE THE SUBROUTINE "IDAYL", CALLED BELOW, REQUIRES IT.
IDC6:
;IDCNV...

	MOVEI C,(AA)		;TIME WITH LH 0 TO C

;ADJUST FOR DAYLIGHT SAVING IF IN EFFECT

	CALL IDAYL		;SKIP IF IN EFFECT (USES C,D,AA,BB)
	JRST .+2
	SUBI C,^D3600		;REAL TIME IS AN HOUR EARLIER
				;DON'T BOTHER TO CORRECT UNDERFLOW YET.

;CONVERT TIME TO GREENWICH AND ADJUST DATE IF NECESSARY

	CALL CNVZON		;GET TIME ZONE IN E AS SECS BEHIND GREENWICH
	 JRST IDCE		;BAD ZONE, GIVE ERROR RETURN
	ADD C,E			;ADD TIME ZONE LAG TO TIME
	CALL FIXDT		;IF TIME NOW NEGATIVE OR TOO BIG,
				;FIX IT BY ADDING OR SUBTRACTING 24 HOURS AND
				;ADJUSTING DATE CORRESPONDINGLY.
	TLNE BB,-1		;CHECK FOR DATE OUT OF 18-BIT RANGE
	JRST [	MOVEI B,DATEX5	;"DATE OUT OF LEGAL RANGE"
		JRST IDCE]

;EXITS

	MUL C,[1B17]		;SHIFT BINARY POINT
	DIVI C,^D<24*3600>	;CONVERT TO FRACTION/DAY
	CAIL D,^D<24*3600/2>	;ROUND
	AOS C
	HRL C,BB		;RETURN DATE IN LH B,
	UMOVEM C,B		;TIME IN RH C.
	UMOVEM AA,C		;TIME ZONE STUFF IN LH C
	SMRETN			;GIVE +2 RETURN TO CALLER

;ERRORS COME HERE, ERROR CODE IN B

IDCE:	UMOVEM B,A		;RETURN ERROR CODE IN A
	MOVE A,B		;GET ERROR CODE IN A
	EMRETN()		;GIVE +1 ERROR RETURN TO CALLER
;SUBROUTINES FOR IDCNV, ODCNV, ETC


;SUBROUTINE TO CHECK VALUES GIVEN FOR YEAR, MONTH, DAY OF MONTH,
; AND TIME, FOR IDCNV AND ODTNC.
;TAKES: B:    YEAR,,MONTH  OR  YEAR,,JULIAN-DAY
;	LH C: DAY OF MONTH OR  0
;	RH AA: TIME	LH AA: FLAGS
;IF BAD, R1 WITH ERROR CODE IN B
;IF OK, R2 WITH DAY OF YEAR IN D (ASSUMING ITS A LEAP YEAR AT THIS
;          POINT), E CLOBBERED.

CKYMDT:	HLRZ E,B		;YEAR
	CAIG E,^D99
	ADDI E,^D1900
	CAIL E,^D1858
	CAILE E,^D2576
	JRST [	MOVEI B,DATEX1	;"ILLEGAL YEAR"
		RET]
	TLNE AA,B3		;JULIAN GIVEN?
	JRST [	MOVEI E,^D365	;YES, ASSUME IT'S NOT A LEAP YEAR
		CALL NLEAP	;IS IT A LEAP YEAR?
		 MOVEI E,^D366	;YES, FIX # OF DAYS
		HRRZ D,B	;GET JULIAN DAY
		CAMG D,E	;TOO BIG?
		SKIPG D		; OR ZERO?
		SKIPA		;YES, ERROR
		SOJA D,CKMDT1	;JULIAN DAY IS OK, MAKE RELATIVE TO 0
		MOVEI B,DATEX7	;ERROR - JULIAN DAY IS OUT OF RANGE
		RET]
	HRRZ E,B		;MONTH
	CAIL E,^D12
	JRST [	MOVEI B,DATEX2	;"MONTH TOO LARGE"
		RET]
	HLRZ D,C		;DAY OF MONTH
	ADD D,DAYS(E)		;ADD DAYS IN PRECEDING MONTHS (ALLOWS A DAY FOR
				;FEB 29 - ADJUSTED LATER IN IDCNV FOR NON-LEAP
				;YEARS)
	CAML D,DAYS+1(E);RESULT MUST NOT BE GREATER THAN NUMBER OF DAYS
				;IN MONTHS INCLUDING THIS ONE
	JRST [	MOVEI B,DATEX3	;"DAY OF MONTH TOO LARGE"
		RET]
CKMDT1:	HRRZ E,AA
	CAIGE E,^D<24*3600>
	RETSKP
	MOVEI B,TIMEX1		;"ILLEGAL TIME"
	RET


;TABLE OF NUMBER OF DAYS IN MONTHS PRECEDING MONTH USED AS TABLE INDEX
;USED BY IDCNV, ODCNV.

DAYS:	EXP 0,^D31,^D60,^D91,^D121,^D152
	EXP ^D182,^D213,^D244,^D274,^D305,^D335,^D366
;SUBROUTINE TO SKIP IF YEAR IN LH B IS NOT A LEAP YEAR
;ALL AC'S PRESERVED.  USED BY IDCNV, ODCNV.

NLEAP:	SAVEAC <E,F>
	HLRZ E,B
	CAIG E,^D99
	ADDI E,^D1900
	IDIVI E,^D4
	JUMPN F,RSKP		;NOT DIVISIBLE BY 4, NOT LEAP YEAR
	IDIVI E,^D25
	JUMPN F,R		;DIVISIBLE BY 4, NOT 100, IS LEAP YEAR
	IDIVI E,^D4
	JUMPN F,RSKP		;DIVISIBLE BY 100, NOT 400, NOT LEAP
	RET			;DIVISIBLE BY 400, IS LEAP YEAR
;SUBROUTINE TO DETERMINE WHETHER DAYLIGHT SAVING TIME SHOULD BE
; APPLIED TO DATE BEING OUTPUT CONVERTED.
;CHANGE THIS ROUTINE FOR LOCAL VARIATIONS IN DAYLIGHT SAVINGS DATES.

;TAKES: B: YEAR,,
;	 C: LOCALIZED SYSTEM FORMAT TIME
;	D: DAY OF YEAR (ALLOWING A DAY FOR FEB 29 ALWAYS)
;	AA: WHAT CAME IN LH D.
;	BB: LOCALIZED SYSTEM FORMAT DATE
;RETURNS IN AA: WHAT TO RETURN IN LH D: B1 ON FOR DAYL SAVING.
;CLOBBERS E,F,G.

;THIS VERSION PUTS DST INTO EFFECT AT 2AM ON THE SUNDAY PRECEEDING
;THE DAY IN DSTON AND ENDS IT AT 2AM (STANDARD TIME) ON THE SUNDAY
;PRECEEDING THE DAY IN DSTOFF, BUT ONLY IF THE YEAR IS GE
;THE YEAR IN DSTBGN.

ODAYL:	TLOE AA,B0		;THIS BIT ON IF CALLER SPECIFIED WHETHER OR
				;NOT TO USE DAYLIGHT SAVING IN B1.
	JRST ODAY9		;CALLER SPECIFIED, GO USE CURRENT B1 VALUE.
	TLZ AA,B1		;CLEAR DAYL BIT
	SKIPE E,DSTFLG		;SPECIAL RULES IN EFFECT?
	JRST [	TXNE E,ALLDST	;DST ALWAYS IN USE?
		JRST ODAY8	;YES
		TXNE E,NEVDST	;DST NEVER IN USE?
		JRST ODAY9	;YES
		JRST .+1]	;NOTA - USE REGULAR ALGORITHM
	HLRZ E,B		;GET YEAR
	CAMGE E,DSTBGN		;AFTER CURRENT LAW WENT INTO EFFECT?
	JRST ODAY9		;NO, NO DST
	CALL NLSS		;GET DST ON DAY TO E, OFF DAY TO F
	CAMN BB,F		;DATE = NLSOCT?
	CAIGE C,^D<2*3600>	;YES, 2AM OR AFTER STD TIME?
	JRST .+2
	RET			;YES AND YES, STD TIME APPLIES.
ODAY6:	CAMN BB,E		;DATE = NLSAPR?
	CAIL C,^D<2*3600>	;YES, BEFORE 2AM?
	JRST .+2
	RET			;YES AND YES, STD TIME.
;AT THIS POINT WE WOULD HAVE RETURNED IF IT WAS NLSAPR OR
;NLSOCT AND TIME OF DAY WAS SUCH THAT STANDARD TIME APPLIED.
;HENCE IF ITS BETWEEN NLSAPR AND NLSOCT INCLUSIVE, 
;DAYLIGHT SAVING APPLIES.
	CAML BB,E		;DATE BEFORE NLSAPR?
	CAMLE BB,F		;OR AFTER NLSOCT?
	RET			;YES, STANDARD TIME APPLIES.
ODAY8:	TLO AA,B1		;SAY USE DAYLIGHT SAVINGS
ODAY9:	TLNE AA,B1
	RETSKP			;SKIP IF DAYLIGHT SAVINGS SHOULD BE USED
	RET
;SUBROUTINE TO SKIP IF DAYLIGHT SAVING TIME SHOULD
;BE APPLIED TO DATE BEING INPUT CONVERTED.
;CHANGE THIS FOR LOCAL VARIATIONS.

;SAME AS ODAYL (PRECEDING) EXCEPT THAT TIME FOR SWITCHING BACK TO
;STANDARD TIME IS 3AM RATHER THAN 2AM BECAUSE TIME IN HAND IS
;DAYLIGHT IF BEFORE 3AM ON NLSOCT.

IDAYL:	TLOE AA,B0
	JRST ODAY9
	TLZ AA,B1
	SKIPE E,DSTFLG		;SPECIAL RULES IN EFFECT?
	JRST [	TXNE E,ALLDST	;DST ALWAYS IN USE?
		JRST ODAY8	;YES
		TXNE E,NEVDST	;DST NEVER IN USE?
		JRST ODAY9	;YES
		JRST .+1]	;NOTA - USER REGULAR ALGORITHM
	HLRZ E,B		;GET YEAR
	CAMGE E,DSTBGN		;AFTER LAW WENT INTO EFFECT?
	JRST ODAY9		;NO, NO DST
	CALL NLSS
	CAMN BB,F		;IS DATE NLSOCT?
	CAIGE C,^D<3*3600>	;YES, 3AM OR AFTER?
	JRST .+2
	RET			;YES AND YES, STANDARD TIME APPLIES.
	JRST ODAY6		;REST IS SAME AS OUTPUT CASE
;COMPUTE DATES OF LAST SUNDAYS IN APRIL, OCTOBER.
;FOR ODAYL, IDAYL.

;DATE OF LAST SUNDAY IN APRIL THIS YEAR (NLSAPR) TO E

NLSS:	MOVE E,BB		;DATE TODAY
	SUB E,D			;-DAY OF YEAR TODAY = BEG OF YEAR
	ADD E,DSTON		;LAST POSSIBLE DAY FOR DST START
	ADDI E,DWFUDG+^D701	;+1 TO MAKE SUNDAY, NOT MONDAY, =0.
				;700 IS ARBITRARY MULTIPLE OF 7 TO MAKE SURE
				;QUANTITY IS POSITIVE DURING DIVISION EVEN
				;IN 1858, WHEN NLSAPR AND NLSOCT ARE NEGATIVE.
	IDIVI E,7		;DIVIDE INTO WEEKS AND DAY OF WEEKS
	IMULI E,7		;CONVERT BACK, DISCARDING DAY OF WEEK
	SUBI E,DWFUDG+^D701	;UNFUDGE AND WE'VE GOT IT!

;DATE OF LAST SUNDAY IN OCTOBER (NLSOCT) THIS YEAR TO F.

	MOVE F,BB
	SUB F,D
	ADD F,DSTOFF		;LAST POSSIBLE DAY FOR DST END
	ADDI F,DWFUDG+^D701
	IDIVI F,7
	IMULI F,7
	SUBI F,DWFUDG+^D701
	RET
;TIME ZONE SUBR FOR IDCNV, ODCNV
;GETS TIME ZONE GIVEN BY CALLER, OR DEFAULTS TO LOCAL AND RETURNS
; THAT TO CALLER OF IDCNV/ODCNV.
;TAKES: AA: WHAT CAME IN LH D. UPDATES SAME.
;RETURNS TIME ZONE, CONVERTED TO MINUTES, IN E.
;SKIP EXCEPT ON ILLEGAL TIME ZONE (ERROR CODE IN B).

CNVZON:	MOVE E,TIMZON		;LOCAL TIME ZONE
	TLOE AA,B2		;SKIP IF CALLER DIDN'T SPEciFY ZONE
	LDB E,[POINT 6,AA,17]	;GET CALLER-SPECIFIED ZONE
	DPB E,[POINT 6,AA,17]	;RETURN ZONE USED TO CALLER
	TRNE E,1B30
	ORCMI E,77		;EXTEND SIGN
	CAML E,[-^D12]
	CAILE E,^D12
	JRST [	MOVEI B,ZONEX1	;"ILLEGAL TIME ZONE"
		RET]
	IMULI E,^D3600		;CONVERT HOURS TO SECONDS
	RETSKP


;SUBROUTINE TO FIX TIME AND ADJUST DATE APPROPRIATELY IF TIME IS
; NEGATIVE OR 24 HOURS OR MORE.
;CALLED IN IDCNV, ODCNV AFTER ADJUSTING FOR TIME ZONE.
;TAKES AND RETURNS:	C: TIME
;			BB: DATE

FIXDT:	JUMPGE C,.+3		;IS TIME NEGATIVE?
	SUBI BB,1		;YES, ITS YESTERDAY, SUBTRACT A DAY FROM DATE,
	ADDI C,^D<24*3600>	;AND ADD A DAY TO TIME.
	CAIGE C,^D<24*3600>	;IS TIME MIDNITE OR AFTER?
	JRST .+3		;(MIDNITE TODAY IS 0)
	ADDI BB,1		;YES, ITS TOMMORROW, ADD A DAY TO DATE,
	SUBI C,^D<24*3600>	;AND SUBTRACT A DAY FROM TIME.
	RET




	END