udfYmdHmsToHTTPStamp
str udfYmdHmsToHTTPStamp (str, int)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfYmdHmsToHTTPStamp (strYmdHms, intMode)
intMode = Min (5, Max (1, intMode)) ; Force intMode range 1..5.
strYear = ItemExtract (1, strYmdHms, ":")
strMonth = ItemExtract (2, strYmdHms, ":")
strDay = ItemExtract (3, strYmdHms, ":")
strHms = StrSub (strYmdHms, 12, 8)
strMonthName = ItemExtract (strMonth, "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", ",")
strDayname = ItemExtract (1 + ((TimeJulianDay (strYmdHms) + 5) mod 7), "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", ",")
Switch intMode
Case 1
   Return StrSub (strDayname, 1, 3) : ", " : strDay : " " : strMonthName : " " : strYear : " " : strHms : " GMT"
Case 2
   Return strDayname : ", " : strDay : "-" : strMonthName : "-" : StrSub (strYear, 3, 2) : " " : strHms : " GMT"
Case 3
   Return StrSub (strDayname, 1, 3) : " " : strMonthName : " " : StrFixLeft (Int (strDay), " ", 2) : " " : strHms : " " : strYear
Case 4
   Return strYear : "-" : strMonth : "-" : strDay : "T" : strHms
Case 5
   Return strYear : strMonth : strDay : "T" : StrReplace (strHms, ":", "")
EndSwitch
;..........................................................................................................................................
; This user defined function "udfYmdHmsToHTTPStamp" returns a string representation of date/time stamps for HTTP applications.
;
; intMode=1 : "Sun, 06 Nov 1994 08:49:37 GMT"  ; RFC 822, updated by RFC 1123
; intMode=2 : "Sunday, 06-Nov-94 08:49:37 GMT" ; RFC 850, obsoleted by RFC 1036
; intMode=3 : "Sun Nov  6 08:49:37 1994"       ; ANSI C"s asctime() format
; intMode=4 : "1994-11-06T08:49:37"            ; ISO 8601 (European Standard EN 28601) (see also German standard DIN 5008)
; intMode=5 : "19941106T084937"                ; ISO 8601 compacted
;
; The first format is preferred as an Internet standard and
; represents a fixed-length subset of that defined by RFC 1123 (an update to RFC 822).
; The second format is in common use, but is based on the obsolete RFC 850 date format and lacks a four-digit year.
;
; HTTP/1.1 clients and servers that parse the date value MUST accept
; all three formats (intMode=1..3) (for compatibility with HTTP/1.0), though they MUST
; only generate the RFC 1123 (intMode=1) format for representing HTTP-date values in header fields.
;
; All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT) without exception.
; For the purposes of HTTP, GMT is exactly equal to UTC (Coordinated Universal Time).
; This is indicated in the first two formats by the inclusion of "GMT"
; as the three-letter abbreviation for time zone, and MUST be assumed when reading the asctime format.
; HTTP-date is case sensitive and MUST NOT include additional linear white spaces.
;
; Detlev Dalitz.20030110.20090728.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strDT = TimeYmdHms ()

strMsgTitle = "Demo: udfYmdHmsToHTTPStamp (strYmdHms, intMode)"
strMsgText = "TimeYmdHms: " : strDT : @LF
strMsgText = strMsgText : @LF : "Mode 1: " : udfYmdHmsToHTTPStamp (strDT, 1)
strMsgText = strMsgText : @LF : "Mode 2: " : udfYmdHmsToHTTPStamp (strDT, 2)
strMsgText = strMsgText : @LF : "Mode 3: " : udfYmdHmsToHTTPStamp (strDT, 3)
strMsgText = strMsgText : @LF : "Mode 4: " : udfYmdHmsToHTTPStamp (strDT, 4)
strMsgText = strMsgText : @LF : "Mode 5: " : udfYmdHmsToHTTPStamp (strDT, 5)

Message (strMsgTitle, strMsgText)
ClipPut (strMsgTitle : @LF : @LF : strMsgText)

Exit

;   Demo: udfYmdHmsToHTTPStamp (strYmdHms, intMode)
;
;   TimeYmdHms: 2009:07:28:20:29:30
;
;   Mode 1: Tue, 28 Jul 2009 20:29:30 GMT
;   Mode 2: Tuesday, 28-Jul-09 20:29:30 GMT
;   Mode 3: Tue Jul 28 20:29:30 2009
;   Mode 4: 2009-07-28T20:29:30
;   Mode 5: 20090728T202930