Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: XMXUTIL1

XMXUTIL1.m

Go to the documentation of this file.
  1. XMXUTIL1 ;ISC-SF/GMB-Date & String Utilities ;04/17/2002 14:14
  1. ;;8.0;MailMan;;Jun 28, 2002
  1. ; All entry points covered by DBIA 2735.
  1. ENCODEUP(XMSUBJ) ; Change ^ to ~U~
  1. F Q:XMSUBJ'[U S XMSUBJ=$P(XMSUBJ,U)_"~U~"_$P(XMSUBJ,U,2,999)
  1. Q XMSUBJ
  1. DECODEUP(XMSUBJ) ; Change ~U~ to ^
  1. F Q:XMSUBJ'["~U~" S XMSUBJ=$P(XMSUBJ,"~U~")_U_$P(XMSUBJ,"~U~",2,999)
  1. Q XMSUBJ
  1. SCRUB(XMSTRING) ; Strip ctrl chars and leading/trailing blanks
  1. S:$E(XMSTRING,1)=" "!($E(XMSTRING,$L(XMSTRING))=" ") XMSTRING=$$STRIP(XMSTRING)
  1. S:XMSTRING?.E1C.E XMSTRING=$$CTRL(XMSTRING)
  1. Q XMSTRING
  1. STRIP(XMSTRING) ; Strip leading and trailing blanks from a string
  1. N I
  1. I $E(XMSTRING,1)=" " D
  1. . F I=2:1 Q:$E(XMSTRING,I)'=" "
  1. . S XMSTRING=$E(XMSTRING,I,999)
  1. I $E(XMSTRING,$L(XMSTRING))=" " D
  1. . F I=$L(XMSTRING):-1 Q:$E(XMSTRING,I)'=" "
  1. . S XMSTRING=$E(XMSTRING,1,I)
  1. Q XMSTRING
  1. MAXBLANK(XMSTRING) ; Reduce 3 or more consecutive blanks in a string to 2
  1. F Q:XMSTRING'[" " D
  1. . S XMSTRING=$P(XMSTRING," ",1)_" "_$P(XMSTRING," ",2,999)
  1. Q XMSTRING
  1. CTRL(XMSTRING) ; Strip control characters from a string
  1. N I
  1. S I=1
  1. F Q:XMSTRING'?.E1C.E D
  1. . F I=I:1 Q:$E(XMSTRING,I)?1C
  1. . S XMSTRING=$E(XMSTRING,1,I-1)_$E(XMSTRING,I+1,999)
  1. Q XMSTRING
  1. MELD(XMSTRING,XMNUMBER,XMLEN) ; Function right-justifies a string and
  1. ; left-justifies a number in a combined string of a given length.
  1. ; The string will be truncated, if necessary.
  1. ; e.g. $$MELD("I just love Lotus, don't you?",123,22) returns:
  1. ; "I just love Lotus 123"
  1. Q:$G(XMNUMBER)="" $E($$LJ^XLFSTR(XMSTRING,XMLEN),1,XMLEN)
  1. S XMLEN=XMLEN-$L(XMNUMBER)-2
  1. Q $E($$LJ^XLFSTR(XMSTRING,XMLEN),1,XMLEN)_" "_XMNUMBER
  1. TSTAMP() ; Timestamp
  1. N X
  1. S X=$H
  1. Q X*86400+$P(X,",",2)
  1. MMDT(XMDT) ; (MailMan Date/Time) Given FM date/time, return external.
  1. ; time is optional
  1. Q:XMDT'=+XMDT XMDT
  1. Q $$FMTE^XLFDT($E(XMDT,1,12),"2Z") ; return mm/dd/yy@hh:mm
  1. N MMDT ; return dd mmm yy hh:mm
  1. I $E(XMDT,4,5)="00" S $E(XMDT,4,5)="01"
  1. I $E(XMDT,6,7)="00" S $E(XMDT,6,7)="01"
  1. S MMDT=$E(XMDT,6,7)_" "_$P("Jan^Feb^Mar^Apr^May^Jun^Jul^Aug^Sep^Oct^Nov^Dec",U,$E(XMDT,4,5))_" "_$E(XMDT,2,3)
  1. S XMDT=$P(XMDT,".",2)_"0000"
  1. Q:'XMDT MMDT
  1. Q MMDT_" "_$E(XMDT,1,2)_":"_$E(XMDT,3,4)
  1. INDT(XMDT) ; (InterNet Date/Time) Given FM date/time, return dd mmm yyyy hh:mm:ss +-hhmm (zone)
  1. I $E(XMDT,4,5)="00" S $E(XMDT,4,5)="01"
  1. I $E(XMDT,6,7)="00" S $E(XMDT,6,7)="01"
  1. S XMDT=$$FMTE^XLFDT(XMDT,"1S")
  1. ; Convert "Jun 28, 1955@10:10:00" to "28 Jun 1955 10:10:00"
  1. S XMDT=+$P(XMDT," ",2)_" "_$P(XMDT," ",1)_" "_+$P(XMDT," ",3)_" "_$S(XMDT["@":$P(XMDT,"@",2),1:"00:00:00")
  1. Q XMDT_" "_^XMB("TIMEDIFF")_" ("_^XMB("TIMEZONE")_")"
  1. CONVERT(X,XMTIME) ; Function to convert Internet dates to FM (returns -1 if error)
  1. ; X Internet date
  1. ; XMTIME =1 Convert time, too; =0 convert date only
  1. ; Formats: Tuesday, 28 June 1955 17:30:45 PDT
  1. ; Tue, 28 Jun 1955 17:30:45 PDT
  1. ; Tue 28 Jun 1955 17:30:45 PDT
  1. ; 28 Jun 1955 17:30:45 -0900 (PST) <== MailMan standard
  1. ; 28 Jun 55 17:30 PST <== Previous MailMan standard
  1. ; Tue Jun 28 17:30:45 PDT 1955
  1. ; 28-JUN-1955 17:30:45 -0400
  1. ; 6/28/55 17:30
  1. ; JUN 28 17:30 1955
  1. N %DT,Y,XMD,XMT
  1. I $E(X)=" "!($E(X)=$C(9)) F S X=$E(X,2,99) Q:$E(X)'=$C(9)&($E(X)'=" ") ; remove leading blanks or tabs
  1. I X?.E2" ".E D ; reduce all consecutive blanks to 1 blank
  1. . N I S I=1
  1. . F S I=$F(X," ",I) Q:I=0 S X=$E(X,1,I-2)_$E(X,I,99),I=I-1
  1. I X?3.A.E D
  1. . I X?3.A1", ".E!(X?3.A1" "3.A.E)!(X?3.A1" "1.2N1" "3.A.E) S X=$P(X," ",2,99) ; remove leading day of week
  1. I $P(X," ",3)[":" D
  1. . S XMD=$P(X," ",1,2)_" "_$P(X," ",$L(X," ")) ; time is before year
  1. . S XMT=$P(X," ",3,$L(X," ")-1)
  1. E D
  1. . S XMD=$P(X," ",1,3) ; year is before time
  1. . I XMD[":" D
  1. . . S XMD=$P(X," ",1) ; "28-JUN-1955 17:30:45 -0400" or "6/28/55 17:30"
  1. . . S XMT=$P(X," ",2,99)
  1. . E S XMT=$P(X," ",4,99)
  1. I $G(XMTIME) Q $$TIMETOO(XMD,XMT)
  1. S X=XMD
  1. D ^%DT
  1. Q Y
  1. TIMETOO(XMD,XMT) ; For internal MailMan use only. Combine date and time, adjusting for difference from GMT.
  1. N XMHH,XMMM,X,Y
  1. I $L(XMT," ")>1 D Q:XMMM=-1 -1
  1. . N XMYT ; 17:30:45 -0800 (PST)
  1. . S XMYT=$TR($P(XMT," ",2),"()")
  1. . D ZONEDIFF(XMYT,.XMHH,.XMMM)
  1. E D
  1. . S (XMHH,XMMM)=0 ; 17:30:45
  1. S XMT=$P(XMT," ",1)
  1. S:$L($P(XMT,":"))=1 XMT="0"_XMT
  1. S XMT=$E(XMT,1,5) ; FM will only handle hh:mm, not :ss
  1. S:XMT="00:00" XMT="00:01" ; if midnight, add a minute
  1. S X=XMD_"@"_XMT
  1. S %DT="T" D ^%DT Q:Y=-1 -1
  1. I 'XMHH,'XMMM Q Y
  1. Q $$FMADD^XLFDT(Y,"",XMHH,XMMM)
  1. ZONEDIFF(XMYT,XMHH,XMMM) ; Given a time zone or time difference from GMT,
  1. ; calculates the hours and minutes difference between that zone and ours
  1. ; XMYT IN: Your Time zone or Time difference from GMT
  1. ; XMHH OUT: The time difference between us in hours
  1. ; XMMM OUT: The time difference between us in minutes
  1. ; XMYTHH Your Time difference from GMT in hours
  1. ; XMYTMM Your Time difference from GMT in minutes
  1. ; XMMT My Time difference from GMT
  1. ; XMMTHH My Time difference from GMT in hours
  1. ; XMMTMM My Time difference from GMT in minutes
  1. N XMMT,XMYTHH,XMYTMM,XMMTHH,XMMTMM
  1. S XMMT=^XMB("TIMEDIFF")
  1. I XMYT=^XMB("TIMEZONE")!(XMYT=XMMT) S (XMHH,XMMM)=0 Q
  1. I XMYT?3A S XMYT=$$GMTDIFF(XMYT) I XMYT="" S XMMM=-1 Q
  1. S XMYTHH=XMYT\100
  1. S XMYTMM=XMYT-(XMYTHH*100)
  1. S XMMTHH=XMMT\100
  1. S XMMTMM=XMMT-(XMMTHH*100)
  1. S XMHH=XMMTHH-XMYTHH
  1. S XMMM=XMMTMM-XMYTMM
  1. Q
  1. ; Also, remember, FM will not handle a 1-digit year
  1. ; If this becomes a problem:
  1. I $L($P(X," ",3))=1 S $P(X," ",3)="0"_$P(X," ",3)
  1. ; *****************************************************
  1. GMTDIFF(XMZONE) ; Given time zone, returns standard internet time difference from GMT
  1. ; XMZONE 3-char time zone name (PST, EDT, etc.)
  1. ; returns difference in hours and minutes (+-hhmm) from GMT
  1. ; e.g. -0230, +1600
  1. ; If time zone can't be found, returns null string
  1. N XMIEN
  1. S XMIEN=$O(^XMB(4.4,"B",XMZONE,0)) Q:'XMIEN ""
  1. S XMDIFF=$P($G(^XMB(4.4,XMIEN,0)),U,3) Q:XMIEN="" ""
  1. Q $$TIMEDIFF(XMDIFF)
  1. TIMEDIFF(XMDIFF) ; Given time difference, returns standard internet time difference.
  1. ; XMDIFF Difference (in hours) from GMT
  1. ; e.g. -2.5 => -0230
  1. ; 16 => +1600
  1. N XMSIGN
  1. I XMDIFF<0 S XMSIGN="-",XMDIFF=-XMDIFF
  1. E S XMSIGN="+"
  1. S XMDIFF=XMDIFF\1*100+(XMDIFF#1*60\1)
  1. Q XMSIGN_$$RJ^XLFSTR(XMDIFF,4,"0")
  1. CONFIRM(XMDUZ,XMZ,XMIM) ; For internal MailMan use only. Send confirmation message to sender.
  1. N XMPARM,XMTO
  1. S XMPARM(1)=XMIM("SUBJ")
  1. S XMPARM(2)=XMV("NAME") S:XMDUZ'=DUZ XMPARM(2)=XMPARM(2)_$$EZBLD^DIALOG(38008,XMV("DUZ NAME")) ; (Surrogate: |1|)
  1. ;S XMPARM(3)=$S($D(^XMB(3.9,XMZ,5)):$P(^(5),U),1:XMZ)
  1. S XMTO=XMIM("FROM")
  1. S XMTO=$S(+XMTO=XMTO:XMTO,1:$$RCPTTO(XMZ))
  1. D TASKBULL^XMXBULL(XMDUZ,"XMRDACK",.XMPARM,"",XMTO)
  1. Q
  1. RCPTTO(XMZ) ; For internal MailMan use only. Return-receipt-to a remote address.
  1. N XMI,XMREC,XMHDR,XMTO
  1. S XMI=0,XMHDR=""
  1. F S XMI=$O(^XMB(3.9,XMZ,2,XMI)) Q:XMI'<1!'XMI S XMREC=^(XMI,0) D Q:$D(XMTO)
  1. . Q:XMREC=""
  1. . S XMHDR=$P(XMREC,":") Q:XMHDR=""
  1. . S XMHDR=$$UP^XLFSTR(XMHDR)
  1. . I XMHDR="RETURN-RECEIPT-TO" S XMTO=$$SCRUB($P(XMREC,":",2,99)) Q
  1. S:'$D(XMTO) XMTO=$P(^XMB(3.9,XMZ,0),U,2)
  1. Q $$REMADDR^XMXADDR3(XMTO)