	FUNCTION CNVRT_MSPTIME, TIME, ERRMSG=ERRMSG
;+
; Project     :	SOHO - CDS/SUMER
;
; Name        :	CNVRT_MSPTIME
;
; Purpose     :	Convert a date/time string from Microsoft Project format.
;
; Explanation :	Reads in a time string which must be in the same format used
;               by Microsoft Project and converts it to CCSDS (The format 
;               recomended by the Consultive Committed for Space Data Systems)
;               The format used by Microsoft Project is:
;
;                       "MMM DD HH:MM XX"  Where -
;
;                        MMM is the three letter month abbreviation
;                        DD  is the day (up to two digits)
;                        HH  is the hour (up to two digits)
;                        MM  is the minuts (must be two digits)
;                        XX  is either AM or PM
;
; Use         :	TIME = CNVRT_MSPTIME (MSP_TIME)
;
;		MSP_TIME = "Jan 12 4:15 PM"
;		PRINT, CNVRT_MSPTIME (MSP_TIME)
;
;               IDL>1996-01-12T16:15:00.000Z
;
; Inputs      :	TIME	 = Time in Micosoft Project format.
;
; Opt. Inputs :	None.
;
; Outputs     :	None.
;
; Opt. Outputs:	None.
;
; Returns     : String containing the time in CCSDS format.
;
; Keywords    :	ERRMSG   = If defined and passed, then any error messages 
;                          will be returned to the user in this parameter 
;                          rather than being handled by the IDL MESSAGE 
;                          utility.  If no errors are encountered, then a 
;                          null string is returned.  In order to use this 
;                          feature, the string ERRMSG must be defined first,
;                          e.g.,
;
;			     ERRMSG = ''
;			     READ_MSP_ITEM, UNIT, TYPE, ITEM, ERRMSG=ERRMSG
;			       IF ERRMSG NE '' THEN ...
;
; Calls       :	STR_SEP
;               NORMAL_STRING
;
; Common      :	None.
;
; Restrictions:	Time must be Microsoft Project format.
;
; Side effects:	None.
;
; Category    :	Planning, science
;
; Prev. Hist. :	None.
;
; Written     :	Ron Yurow, 25 October 1995
;
; Modified    :	Version 1, Ron Yurow, 25 October 1995
;
; Version     :	Version 1, Ron Yurow, 25 October 1995
;-
;
	ON_ERROR, 2
;
;  Check the input parameters.
;
	IF N_PARAMS() LT 1 THEN BEGIN
		MESSAGE = 'Syntax:  MAKE_ECS_TIME, TIME'
		GOTO, HANDLE_ERROR
	ENDIF

;
;  Get rid of any extra white space.
;  

        NWTIME = STRCOMPRESS (STRTRIM (TIME, 2)) 

;
;  Now, convert the string to upper case.
;

        NWTIME = STRUPCASE (NWTIME)

;
;  Use STR_SEP to seperate the time/date string into its component parts.
;


        TIME_FIELD = STR_SEP (NWTIME, " ")

; 
;  Check if the time string seems to be in the expected format.
;

	IF N_ELEMENTS (TIME_FIELD) NE 4 THEN BEGIN
		MESSAGE = 'Time String is not in the expected format for '
                MESSAGE = MESSAGE + 'Microsoft Project.'
		GOTO, HANDLE_ERROR
	ENDIF

;
;  Set up the month abbreviation table.
;

        MONTHTBL = ['JAN',        $
                    'FEB',        $
                    'MAR',        $
                    'APR',        $
                    'MAY',        $
                    'JUN',        $
                    'JUL',        $
                    'AUG',        $
                    'SEP',        $
                    'OCT',        $
                    'NOV',        $
                    'DEC']

;
; Convert the month into a number.
;

        FOR I = 0, 11 DO BEGIN
           IF MONTHTBL (I) EQ STRMID (TIME_FIELD (0), 0, 3) THEN BEGIN
              MONTH = I + 1
              GOTO, LOOP_EXIT
           ENDIF
        ENDFOR

LOOP_EXIT :

;
; Convert the the day into a number.
;

        DAY = 0
        READS, TIME_FIELD (1), DAY

 
;
; Break up the Hour/Minutes field into seperate strings, seperated by a ":".
;

        HOUR = 0
        MIN  = 0
       
        HOUR_FIELD = STR_SEP (TIME_FIELD (2), ":")

; 
;  Another check to see if the time string seems to be in the 
;  expected format.
;

	IF N_ELEMENTS (HOUR_FIELD) NE 2 THEN BEGIN
		MESSAGE = 'Time String is not in the expected format for '
                MESSAGE = MESSAGE + 'Microsoft Project.'
		GOTO, HANDLE_ERROR
	ENDIF

;
; Get the HOUR and MIN (Minutes) from the time string.
;

        READS, HOUR_FIELD (0), HOUR
        READS, HOUR_FIELD (1), MIN

;
; Set the PM flag.  If this set to 1 (TRUE) it will indicate that the HOUR
; should be advanced by 12 to convert to 24 Hour time format.
;  

        PM = 0
        IF 'PM' EQ STRMID (TIME_FIELD (3), 0, 2) THEN PM = 1


;
; Convert HOUR to 24 hour time.
;

        IF PM EQ 1 THEN HOUR = HOUR + 12

;  
; Get the current time.
;
 
        TIME_NOW = ''
        GET_UTC, TIME_NOW, /CCSDS

;
; Get the current month and year.
;

        MONTH_NOW = 0
        YEAR_NOW  = 0

        READS, STRMID (TIME_NOW, 0, 4), YEAR_NOW;
        READS, STRMID (TIME_NOW, 5, 2), MONTH_NOW

;
; Decide if the date refers to this year or next.
;

        YEAR = YEAR_NOW
        IF MONTH_NOW GT MONTH THEN YEAR = YEAR_NOW + 1


;
; Now write out the new time string in CCSDS format.
;

        FORMAT_STR = '($, I4.4, 2("-", I2.2), "T", 2(I2.2, ":"), "00.000Z")'  

        NWTIME = STRING (YEAR, MONTH, DAY, HOUR, MIN, FORMAT = FORMAT_STR)

;
; Were done, so return.
; 


        RETURN, NWTIME

;
;  Error handling point.
;
HANDLE_ERROR:
	IF N_ELEMENTS(ERRMSG) EQ 0 THEN MESSAGE, MESSAGE, /CONTINUE	$
		ELSE ERRMSG = 'CNVRT_MSPTIME: ' + MESSAGE
	RETURN, ''
	END

