OpenVMS Source Code Demos

WCSM_GET_MIME_TIME

	function string wcsm_get_mime_time					!
	!==========================================================================================
	! Title  : wcsm_get_mime_time_xxx.fun (see: RFC 822)
	! Author : Neil Rieck
	! History:
	! ver  who when   what
	! ---- --- ------ --------------------------------------------------------------------------
	!    3 NSR 090514 1. dervived from wcsm_get_gmt_time_2.fun (Dave McNeil)
	!    4 NSR 110316 1. added documentation reguarding logical SYS$TIMEZONE_DIFFERENTIAL
	!		  2. tweaked the code
	!      NSR 141122 3. update documentation
	!==========================================================================================
	! Purpose:		returns a string like this:
	!				Thu, 14 May 2009 12:01:01 -0400
	! Dependancies:		wcsm_trnlnm must be included in calling application's source.
	!==========================================================================================
	option type=explicit							!
	!
	!	Our variables
	!
	declare basic$quadword	quad_time					!
	declare long		rc%, dt_context%, component%			!
	declare double		data_to_test, seconds, minutes, hours, yada	!
	declare string		result$, tz_diff$, tz_name$			!
	!
	!	Include some stuff from the system library
	!
	%include "starlet"	%from %library "sys$library:basic$starlet"
	%include "lib$routines"	%from %library "sys$library:basic$starlet"
	%include "$libdtdef"	%from %library "sys$library:basic$starlet"
	!
	!	External stuff
	!
	external string function wcsm_trnlnm(string, string)			!
	!
	! Note:	these logical names will only change if "set_vms_logicals" is added to file TCPWARE:NTP.CONF
	!		or
	!	SYSGEN parameter: AUTO_DLIGHT_SAV = 1
	!
	tz_name$ = wcsm_trnlnm("SYS$TIMEZONE_NAME"        , "LNM$SYSTEM_TABLE")	!
	tz_name$ = "EDT"	if tz_name$ = ""				! default to EDT
!~~~	tz_name$ = "EST"	if tz_name$ = ""				x default to EST
	!
	tz_diff$ = wcsm_trnlnm("SYS$TIMEZONE_DIFFERENTIAL", "LNM$SYSTEM_TABLE")	!
	tz_diff$ = "-14400"	if tz_diff$ = ""				! default to EDT
!~~~	tz_diff$ = "-16000"	if tz_diff$ = ""				x default to EST
	!
	!	Notes:	1. the value of SYS$TIMEZONE_DIFFERENTIAL is given in seconds before/after GMT
	!		2. +HHMM is described in ISO-8601
	!
	!	  data	+HHMM	zone	zone	zone	zone	notes
	!	------	-----	-----	----	----	----	----------------
	!	-18000	-0500	UTC-5	EST			Eastern Standard
	!	-14400	-0400	UTC-4	EDT	AST		Eastern Daylight / Atlantic Standard
	!	-10800	-0300	UTC-3	ADT			Atlantic Daylight
        !       -12600  -0330				NST	Newfoundland Standard
        !        -9000  -0230				NDT	Newfoundland Daylight
	!
	when error in								!
	    data_to_test = real(tz_diff$, DOUBLE)				!
	    seconds = abs(data_to_test)						! make sure this is positive
	    hours = integer(seconds / 3600.0)					! compute hours
	    yada = seconds - (hours * 3600.0)					! remainder is minutes
	    minutes = integer(yada / 60.0)					!
	    !
	    tz_diff$ =	format$(hours,	"<0>#")	+				&
			format$(minutes,"<0>#")					!
	    !
	    if data_to_test < 0 then						!
		tz_diff$ = "-"+ tz_diff$					! the spec requires minus
	    else								!
		tz_diff$ = "+"+ tz_diff$					! the spec suggests we need plus
	    end if								!
	use									! oops
	    tz_diff$ = tz_name$							! use this older format
	end when								!
	!
	rc% = sys$gettim(quad_time)						! get current system time
	dt_context% = 0								!
	component% = LIB$K_OUTPUT_FORMAT					!
	rc% = lib$init_date_time_context(dt_context%, component%, "|!WAC, !D0 !MAAC !Y4|!H04:!M0:!S0|")
	rc% = lib$format_date_time(result$, quad_time, dt_context%,,)		!
	result$ = result$ +" "+ tz_diff$					!
	!
	wcsm_get_mime_time = result$						!
	end function 								!