home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rxdates.zip
/
rxdates.CMD
next >
Wrap
OS/2 REXX Batch file
|
1994-09-18
|
7KB
|
196 lines
/* rexx routine(s) to change date formats */
/* startdescription
This routine is normally meant to be Called from another Rexx routine.
It can be used from the command line though. I left it that way for my
testing.
It has not been optimized, but seems to work fine. There is no error
checking, so you should do your own outside this routine.
If you find errors or additions, you have the source to fix it <grin>.
Denis Tonn 1:153/908@fidonet DTONN@IBM.VNET.COM
Dates types to be processed can be:
Julian (day # of year)
USA (MM/DD/YY or MM/DD/YYYY)
Month Day Year (eg: January 17 1994)
BaseDate (total days since 01/01/01)
NOTE: Julian dates assume current year. Because of this, BaseDates less than
366 are processed as Julian. Also, to properly handle MM/DD/YYYY
requires that MM/DD/YY be restricted to the current century.
Returned types available are:
'J' - Julian format of date (173)
'U' - USA format (MM/DD/YY)
'F' - Full format (October 23 1992)
'D' - Day number of the week (0 to 6, where 0 is Monday)
'W' - Weekday name (Thursday)
'M' - Month name (June)
'B' - Basedate (days since 01/01/01)
'L' - Leapyear - Rexx boolean (0/1) value. True if leapyear
Format for a call from another rexx routine would be:
USA=rxdates('Febuary 27 1993 U') - returns the USA format
Julian=rxdates(08/07/93 'J') - returns the julian date for 08/07/1993
Weekday=rxdates(37 W) - returns the name/day of the week from day 37 this year
basedate=rxdates('09/03/1954 B') - returns days from 01/01/0001 to 09/03/1954
I find it particularly useful in calculating future/past dates. Lets say I
want to calculate the MM/DD/YY format of a date 30 days ahead, when my starting
date is today. End of month crossovers and leapyear calculation can make this
tricky.. So:
newUSA=rxdates((date('B')+30) 'U')
See sample command file for other formats.
enddescription */
/* trace results */
/* low level stuff. Days in a month, month names, etc */
months.names= 'January Febuary March April May June July August September October November December'
months.days= '31 28 31 30 31 30 31 31 30 31 30 31 '
julian_total=365
week.days='Monday Tuesday Wednesday Thursday Friday Saturday Sunday'
parse source . how myfile /* how was I called? from Command line or rexx program */
if arg()<1 then
do
say filespec('n',myfile) 'inputdate outputtype'
I=1
do until pos('STARTDESCRIPTION',translate(sourceline(I)))<>0
I=I+1
end /* do */ /* found starting of description */
I=I+1
do until pos('ENDDESCRIPTION',translate(sourceline(I)))<>0
say sourceline(I)
I=I+1
end /* do */ /* found end of description */
exit
end /* do */
arg month day year type /* max possible args */
if words(month)>1 then /* command line call, split it up */
parse var month month day year type
if datatype(month,'NUM') then
do
type=day
if month<=366 then /* assume julian format of date */
do
Julian=month
parse value date('N') with . . year /* assume current year */
call correct_leapyear
I=1; mm=1; dd=julian
do while dd>word(months.days,mm)
dd=dd-word(months.days,mm)
mm=mm+1
end /* do */
day=dd; month=word(months.names,mm)
end /* do */
else /* assume basedate format */
do
basedate=month
y400=basedate%146097; r400=basedate//146097
y100=r400%36524; r100=r400//36524
y4=r100%1461; r4=r100//1461
y1=r4%365; julian=(r4//365)+1
year=(y400*400)+(y100*100)+(y4*4)+y1+1
call correct_leapyear
I=1; mm=1; dd=julian
do while dd>word(months.days,mm)
dd=dd-word(months.days,mm)
mm=mm+1
end /* do */
day=dd; month=word(months.names,mm)
end /* do */
end /* do datatype=num */
else
do
if pos('/',month)<>0 then /* MM/DD/YY format */
do
type=day
parse var month MM '/' DD '/' YY
parse value date('N') with . . year
if YY<100 then year=((year%100)*100)+YY /* assume current century */
else year=YY
call correct_leapyear
month=word(months.names,abs(MM))
day=abs(dd)
end /* do */
else
do /* must be full name */
call correct_leapyear
end /* do */
end /* do */
call init_tables
Type=translate(left(type,1))
if translate(left(how,1))='C' then
do
select
when type='J' then say 'Julian date: 'julian
when type='U' then say 'USA date: 'Usa
when type='F' then say 'Full date: 'month day year
when type='D' then say 'Day number: 'dayweek
when type='W' then say 'Weekday : 'weekday
when type='M' then say 'Month : 'month
when type='B' then say 'basedate : 'basedate
when type='L' then say 'leapyear : 'leapyear(year)
otherwise
say 'Date:' month day year 'Julian:'julian 'Weekday:'weekday 'USA:'Usa 'BaseDate:'basedate
end /* select */
end /* do */
else
do
select
when type='J' then return(julian)
when type='U' then return(Usa)
when type='F' then return(month day year)
when type='D' then return(dayweek)
when type='W' then return(weekday)
when type='M' then return(month)
when type='B' then return(basedate)
when type='L' then return(leapyear(year))
otherwise
return(0)
end /* select */
end /* do */
exit
init_tables:
baseyear=(365*(year-1))+((year-1)%4)-((year-1)%100)+((year-1)%400)-1 /* the number of days since 01/01/0001 to 01/01/xxxx */
dd=day; yy=(year//100); mm=1
do while translate(left(word(months.names,mm),3)) <> translate(left(month,3))
mm=mm+1
end /* do */
month=word(months.names,mm); julian=0
do I=1 to mm-1
julian=julian+word(months.days,I)
end /* do */
if length(dd)<2 then dd='0'||dd
if length(mm)<2 then mm='0'||mm
if length(yy)<2 then yy='0'||yy
usa=mm'/'dd'/'yy; julian=julian+day; basedate=baseyear+julian
dayweek=basedate//7; weekday=word(week.days,dayweek+1)
return
correct_leapyear:
if leapyear(year) then
do
months.days= '31 29 31 30 31 30 31 31 30 31 30 31 '
julian_total=366
end /* do */
return
leapyear: procedure /* determines if the passed year is a leapyear */
arg year
if (year//100)<>0 then /* not a century year */
return((year//4)=0) /* true if leap year */
else /* century year */
return(year//400=0) /* century leapyear every 400 years */