home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
DATEFMT.SRF
< prev
next >
Wrap
Text File
|
1996-09-27
|
7KB
|
234 lines
/* Convert, using c strftime format,a time-date formatted string */
/* with thanks to Chris Madsen (ac608@yfn.usy.edu) for the documentation
on the strtftime function
Expects:
conversion string
date in 'B' format
time in hh:mm:ss
if no date or time, use current date & time
*/
/*parse pull foo
say sref_datetime_convert('%'foo)
exit*/
sref_datetime_convert:
parse arg thestring,adate,atime
if adate='' then adate=DATE('B')
if atime=' ' then atime=time('N')
daysht='Sun Mon Tue Wed Thu Fri Sat '
daylong='Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
monthlong='January February March April May June July August September October November December '
monthsht='Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec '
/* uses sref_replacestrg extensively ... */
doit=thestring
if pos('%%',doit)>0 then do
foo='1a'x
doit=sref_replacestrg(doit,'%%',foo,'ALL','YES')
end
if pos('%a',doit)>0 then do /* Mon Tue .. */
foo=dateconv(adate,'B','w')
aa=wordpos(upper(foo),upper(daylong)) ;
foo=word(daysht,aa)
doit=sref_replacestrg(doit,'%a',foo,'ALL','YES')
end
if pos('%A',doit)>0 then do /* MONDAY TUESDAY */
foo=dateconv(adate,'B','w')
doit=sref_replacestrg(doit,'%A',foo,'ALL','YES')
end
if pos('%b',doit)>0 then do /* Jan Feb .. */
foo=dateconv(adate,'B','M')
aa=wordpos(upper(foo),upper(monthlong))
foo=word(monthsht,aa)
doit=sref_replacestrg(doit,'%b',foo,'ALL','YES')
end
if pos('%B',doit)>0 then do /* January February */
foo=dateconv(adate,'B','M');
doit=sref_replacestrg(doit,'%B',foo,'ALL','YES')
end
if pos('%c',doit)>0 then do /*date and time */
foo2=dateconv(adate,'B','N')
foo=atime' 'foo2
doit=sref_replacestrg(doit,'%c',foo,'ALL','YES')
end
if pos('%d',doit)>0 then do /* 1 2 .. 31 day of month */
foo=dateconv(adate,'B','N') ; foo=strip(word(foo,1))
doit=sref_replacestrg(doit,'%d',foo,'ALL','YES')
end
if pos('%D',doit)>0 then do /* 05/27/89 */
foo=dateconv(adate,'B','U')
doit=sref_replacestrg(doit,'%D',foo,'ALL','YES')
end
if pos('%e',doit)>0 then do /* 1 2 .. 31 day of month, space padded*/
foo=dateconv(adate,'B','N') ; foo=' '||strip(word(foo,1))||' ' /* must be used with <PRE> */
doit=sref_replacestrg(doit,'%e',foo,'ALL','YES')
end
if pos('%h',doit)>0 then do /* Jan Feb .. */
foo=dateconv(adate,'B','m'); aa=wordpos(upper(foo),upper(monthlong))
foo=word(monthsht,aa)
doit=sref_replacestrg(doit,'%h',foo,'ALL','YES')
end
if pos('%H',doit)>0 then do /* 00.. 23 hour*/
parse var atime foo ':' .
doit=sref_replacestrg(doit,'%H',foo,'ALL','YES')
end
if pos('%I',doit)>0 then do /*01 .. 12 hour*/
parse var atime foo2 ':' .
if foo2=0 then foo2=12
if foo2>12 then foo2=foo2-12
doit=sref_replacestrg(doit,'%I',foo2,'ALL','YES')
end
if pos('%j',doit)>0 then do /* 01..366 day of year */
foo=dateconv(adate,'B','D')
doit=sref_replacestrg(doit,'%j',foo,'ALL','YES')
end
if pos('%m',doit)>0 then do /* 01 - 12 month */
foo=dateconv(adate,'B','L') ; foo=word(foo,2) ;
foo=wordpos(foo,monthlong)
doit=sref_replacestrg(doit,'%m',foo,'ALL','YES')
end
if pos('%M',doit)>0 then do /* 00...59 minute*/
parse var atime foo1 ':' foo2 ':' .
doit=sref_replacestrg(doit,'%M',foo2,'ALL','YES')
end
if pos('%n',doit)>0 then do /* new line */
foo='<BR>'
doit=sref_replacestrg(doit,'%n',foo,'ALL','YES')
end
if pos('%p',doit)>0 then do /* am or pm */
parse var atime hh ':' .
if hh >11 then
foo='pm'
else
foo='am'
doit=sref_replacestrg(doit,'%p',foo,'ALL','YES')
end
if pos('%r',doit)>0 then do /* 8:35pm */
parse var atime hh ':' mm ':' ss
if hh>11 then
pp='pm'
else
pp='am'
if hh=0 then hh=12
if hh>12 then hh=hh-12
foo=hh':'mm':'ss':'pp
doit=sref_replacestrg(doit,'%r',foo,'ALL','YES')
end
if pos('%S',doit)>0 then do /* 00-59 scones */
parse var atime hh ':' mm ':' foo
doit=sref_replacestrg(doit,'%S',foo,'ALL','YES')
end
if pos('%t',doit)>0 then do /* tab (better use in a <PRE> */
foo='09'x
doit=sref_replacestrg(doit,'%t',foo,'ALL','YES')
end
if pos('%T',doit)>0 then do /* 13:54:12 */
foo=atime
doit=sref_replacestrg(doit,'%T',foo,'ALL','YES')
end
if pos('U',doit)>0 then do /* week # (00-53 -- 1 on first suuda */
today=dateconv(adate,'B','D')
a=dateconv(1,'D','W')
nday_jan1=wordpos(upper(a),upper(daylong))
offset=0
if nday_jan1 > 1 then
offset=8-nday_jan1
t1=today-offset
if t1 <= 0 then
isweek=0
else
isweek=trunc(t1/7)+1
doit=sref_replacestrg(doit,'%U',isweek,'ALL','YES')
end
if pos('%w',doit)>0 then do /* 0--6 weekday (sunday=0) */
foo=dateconv(adate,'B','W')
aa=wordpos(upper(foo),upper(daylong))-1
doit=sref_replacestrg(doit,'%w',aa,'ALL','YES')
end
if pos('%W',doit)>0 then do /* week # (00-53 -- 1 on first monday */
today=dateconv(adate,'B','D')
a=dateconv(1,'D','W')
nday_jan1=wordpos(upper(a),upper(daylong))-1
if nday_jan1=0 then nday_jan1=7
offset=0
if nday_jan1 > 1 then
offset=8-nday_jan1
t1=today-offset
if t1 <= 0 then
isweekm=0
else
isweekm=trunc(t1/7)+1
doit=sref_replacestrg(doit,'%W',isweekm,'ALL','YES')
end
if pos('%x',doit)>0 then do /* 27 August 1988 */
foo=dateconv(adate,'B','L')
doit=sref_replacestrg(doit,'%x',foo,'ALL','YES')
end
if pos('%X',doit)>0 then do /* 13:01:09 */
foo=time('N')
doit=sref_replacestrg(doit,'%X',foo,'ALL','YES')
end
if pos('%y',doit)>0 then do /* 00-99 year */
foo=dateconv(adate,'B','L') ; foo=right(foo,2)
doit=sref_replacestrg(doit,'%y',foo,'ALL','YES')
end
if pos('%Y',doit)>0 then do /* 1901 year */
foo=dateconv(adate,'B','L') ; foo=strip(word(foo,3))
doit=sref_replacestrg(doit,'%Y',foo,'ALL','YES')
end
if pos('%Z',doit)>0 then do
foo=value('TZ',,'os2environment') ; foo=left(foo,3)
doit=sref_replacestrg(doit,'%Z',foo,'ALL','YES')
end
if pos('1a'x,doit)>0 then do
doit=sref_replacestrg(doit,'1a'x,'%','ALL','YES')
end
return doit