home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / timezn_c.zip / TZ1.CMD < prev    next >
OS/2 REXX Batch file  |  1996-04-29  |  7KB  |  230 lines

  1. /* OS/2 Rexx Script for MR/2 ICE     */
  2. /* by William H. Geiger III 07 Apr 96 */
  3. /* Geiger Consulting                    */
  4. /* whgiii@amaranth.com                */
  5. /* this script will convert the Date: stamp in the header of messages */
  6. parse arg msg_filename                          /* get filename */
  7. st=stream(msg_filename,'c','open')            /* open file */
  8. cnt=0                                             /* initialize vars. */
  9. /* local time zone stamp 
  10. enter your local time zone stamp here must be in the format of +1200 to -1200 or GMT */
  11. tz1='-0600'
  12. /* end local time zone stamp */
  13. xx4=0
  14. xx6='Old TimeStamp:'
  15. yy1='Date:'
  16. yy2='X-Mailer:'
  17. yy3='From:'
  18. yy4='MR/2'
  19. lin=''
  20. gb=0
  21. day_of_week="Sun Mon Tue Wed Thu Fri Sat"
  22. month_of_year="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
  23. days_31="Jan Mar May Jul Aug Oct Dec"
  24. days_30="Apr Jun Sep Nov"
  25. nxy=1
  26. do forever while (length(linein(msg_filename))>0)                        /* pull info from file header */
  27. nxx=stream(msg_filename,'c','seek +0')                                   /* get read pointer */
  28. nxx_rs=stream(msg_filename,'c','seek =' nxy)                            /* reset read pointer */
  29. xx1=0
  30. xx2=0
  31. xx3=0
  32. xx7=0
  33. cnt=cnt+1
  34. lin=linein(msg_filename)
  35. nxy=stream(msg_filename,'c','seek +0')
  36. xx1=pos(yy1,lin,1)
  37. xx2=pos(yy2,lin,1)
  38. xx3=pos(yy3,lin,1)
  39. xx7=pos(xx6,lin,1)
  40. If xx1>0 then do
  41.           dt=lin
  42.           dt_no=cnt
  43.           end
  44. If xx2>0 then mail=lin
  45. If xx3>0 then from=lin
  46. If xx7>0 then do
  47.    goodby='already done!!!'
  48.    gb=1
  49.    st1=stream(msg_filename,'c','close')
  50.    call goodby
  51. end  /* Do */
  52. end
  53. st1=stream(msg_filename,'c','close')
  54. parse value dt with xx5 dowt date mont yr tm tz tzt
  55. if words(dt)<7 then do
  56.    goodby='words'
  57.    gb=0
  58.    call goodby
  59. end  /* Do */
  60. if pos(',',dowt)=0 then do
  61.    goodby='no day of week'
  62.    gb=0
  63.    call goodby
  64. end  /* Do */
  65. dowt=substr(dowt,(length(dowt)-3),3)                           /* remove coma from day of week */
  66. dow=wordpos(dowt,day_of_week)                /* convert day of week to # */
  67. mon=wordpos(mont,month_of_year)              /* convert month to # */
  68. if trunc(yr/4)=(yr/4) then leap=1                /* calc last day of month from source */
  69. else leap=0
  70. if wordpos(mont,days_31)>0 then ld=31
  71. else if wordpos(mont,days_30)>0 then ld=30
  72.      else ld=28+leap
  73. if mon=1 then mon_prv=12
  74. else mon_prv=mon-1
  75. mont_1=word(month_of_year,(mon_prv))          /* calc last day of previous month from source */
  76. if wordpos(mont_1,days_31)>0 then ld_1=31
  77. else if wordpos(mont_1,days_30)>0 then ld_1=30
  78.      else ld_1=28+leap
  79. if datatype(tz,'N')=1 then do       /* check timzone stamp */
  80.     if tz=0 then tz=0
  81.       else tz=strip(tz,t,0)
  82.       end  /* Do */
  83.     else if translate(tz)=='GMT' then tz=0
  84.          else if translate(tz)=='UTC' then tz=0
  85.          else if translate(tz)=='UT' then tz=0
  86.          else if translate(tz)=='EST' then tz=-05
  87.          else if translate(tz)=='EDT' then tz=-05
  88.          else if translate(tz)=='CST' then tz=-06
  89.          else if translate(tz)=='CDT' then tz=-06
  90.          else if translate(tz)=='MST' then tz=-07
  91.          else if translate(tz)=='MDT' then tz=-07
  92.          else if translate(tz)=='PST' then tz=-08
  93.          else if translate(tz)=='PDT' then tz=-08
  94.          else do
  95.             goodby="bad TZ =" tz
  96.             gb=0
  97.             call goodby
  98.          end  /* Do */
  99. if datatype(tz1,'N')=1 then do
  100.    if tz1=0 then tz1=0
  101.       else tz1=strip(tz1,t,0)
  102.    end
  103.    else if tz1=='GMT' then tz1=0
  104.          else if translate(tz)=='UTC' then tz=0
  105.          else if translate(tz)=='UT' then tz=0
  106.          else if translate(tz)=='EST' then tz=-05
  107.          else if translate(tz)=='EDT' then tz=-05
  108.          else if translate(tz)=='CST' then tz=-06
  109.          else if translate(tz)=='CDT' then tz=-06
  110.          else if translate(tz)=='MST' then tz=-07
  111.          else if translate(tz)=='MDT' then tz=-07
  112.          else if translate(tz)=='PST' then tz=-08
  113.          else if translate(tz)=='PDT' then tz=-08
  114.          else do
  115.             goodby= 'bad TZ1=' tz1
  116.             gb=0
  117.             call goodby
  118.          end  /* Do */
  119. parse value tm with hr ':' mn ':' sc                               /* parse time into hrs, mins, secs */
  120. hr1=hr-tz+tz1                                   /* calc new time */
  121. if hr1<0 then call new_day
  122.    else if hr1>23 then call old_day
  123.    else do
  124.       dow1=dow
  125.       date1=date
  126.       mon1=mon
  127.       yr1=yr
  128.    end
  129. mn1=mn
  130. sc1=sc
  131. if length(hr1)=1 then hr1=insert('0',hr1)
  132. tm1=''                                                  /* combine vars to create tm1 (new time) */
  133. tm1=insert(sc1,tm1)
  134. tm1=insert(':',tm1)
  135. tm1=insert(mn1,tm1)
  136. tm1=insert(':',tm1)
  137. tm1=insert(hr1,tm1)
  138. mont1=word(month_of_year,mon1)                     /* convert month # to text */
  139. dowt1_tmp=word(day_of_week,dow1)                  /* convert day of week # to text */
  140. dowt1=','
  141. dowt1=insert(dowt1_tmp,dowt1)
  142. tz1_tmp='00'
  143. tz1=insert(tz1,tz1_tmp)
  144. tz=insert(tz,tz1_tmp)
  145. If length(date1)=1 then date1=insert('0',date1)
  146. If length(yr1)=1 then yr1=insert('0',yr1)
  147. dt1=''
  148. dt1=xx5 dowt1 date1 mont1 yr1 tm1 tz1
  149. dt2=xx6 dowt',' date mont yr tm tz
  150. dttm=date('N') Time() msg_filename
  151. '@echo off'
  152. copy msg_filename 'temp.msg' '>>null'
  153. '@echo off'
  154. erase msg_filename '>>null'
  155. st3=stream('temp.msg','c','open')               /* re-write msg file with new timestamp */
  156. st4=stream(msg_filename,'c','open')
  157. wrt1=0
  158. do forever while lines('temp.msg')>0
  159.    wrt1=wrt1+1
  160.    lnin = linein('temp.msg')
  161.       If wrt1=dt_no then do
  162.               call lineout msg_filename,dt1
  163.               call lineout msg_filename,dt2 
  164.               wrt1=wrt1+1
  165.          end
  166.    else call lineout msg_filename,lnin
  167. end /* do */
  168. st3=stream('temp.msg','c','close')
  169. st4=stream(msg_filename,'c','close')
  170. erase 'temp.msg >> null'
  171. goodby= 'all done'
  172. gb=1
  173. call goodby
  174.  
  175. old_day:                                        /* subtract a day routine */
  176. hr1=hr1-24
  177. dow1=dow-1                                   /* calc day of week */
  178. if dow1=0 then dow1=7
  179. If date>1 then do
  180.       date1=date-1
  181.       mon1=mon
  182.       yr1=yr
  183.    end
  184.    else call old_month
  185. return
  186.  
  187. new_day:                                       /* add a day routine */
  188. hr1=hr1+24
  189. dow1=dow+1
  190. if dow1=8 then dow1=1
  191. if date<ld then do
  192.    date1=date+1
  193.    mon1=mon
  194.    yr1=yr
  195. end  /* Do */
  196. else call new_month
  197. return
  198.  
  199. old_month:                                    /* subtract a month routine */
  200. date1=ld_1
  201. if mon=1 then do                              /* If source month is Jan the change month */
  202.    mon1=12                                    /* to Dec and subtract 1 year */
  203.    yr1=yr-1
  204. end  
  205. else do
  206.    mon1=mon-1                          /* Otherwise subtract 1 month */
  207.    yr1=yr
  208. end  
  209. return
  210.  
  211. new_month:                                   /* add a month routine */
  212. date1=1
  213. if mon=12 then do
  214.    mon1=1
  215.    yr1=yr+1
  216. end  /* Do */
  217. else do
  218.    mon1=mon+1
  219.    yr1=yr
  220. end  /* Do */
  221. return
  222.  
  223. goodby:                                       /* exit routine */
  224. stm_gb=stream(msg_filename,'c','close')
  225. if gb=0 then do
  226.    gb_nm_err= date('N') time() goodby msg_filename
  227.    call lineout 'error.log', gb_nm_err
  228. end  /* Do */
  229. exit
  230.