home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
fdater.zip
/
FDATER.DOC
< prev
next >
Wrap
Text File
|
1995-04-29
|
8KB
|
170 lines
======================================================================
FDATER.REX
A Rexx implementation of the Truedate date arithmetic routine
Revision date of this file: 1995 Apr 29
======================================================================
AUTHOR: Stephen Ferg
608 N. Harrison Street
Arlington, VA 22203-1416
USA
telephone (voice, not FAX): (703) 525-2241
CompuServe ID : 73377,1157
Internet : ferg_s@bls.gov
Internet : 73377.1157@compuserve.com
=====================================================================
FDATER.REX is a REXX module for doing date arithmetic.
FDATER is intended for business applications, not historical ones.
The source code of FDATER.REX has been placed in the public domain by
its author, Stephen Ferg. You may copy, use, and modify it as you wish.
To avoid confusion, although the actual source code of FDATER.REX has
been placed in the public domain, its author, Stephen Ferg, wishes to
retain copyright of the names "FDATER" and "FDATER.REX". You may copy,
use, and modify the code as you wish, but if you change it, please do
not distribute the modified version under the names "FDATER" or
"FDATER.REX", and please document any modifications that you have made
to the original code.
FDATER.REX is a REXX implementation of the TRUEDATE algorithm that is
presented in the article in the file TRUEDATE.TXT. The main
modification to the Truedate routines for the REXX implementation was to
add code to convert REXX "base" dates to and from Truedate "absolute"
dates. This was necessary because Truedate and REXX have different
conceptions of what a "base" date is. On 1/1/1, Truedate will tell you
that today is day 1, but REXX's DATE function with the "B" parm will
tell you that 0 days have elapsed. So Truedate and REXX's DATE function
are one day out of sync. FDATER.REX contains code to compensate for
this difference. It accepts REXX base dates through its interface, but
converts them to/from Truedate "absolute dates" for internal use.
FDATER'S BUSINESS VIEW OF THE CALENDAR
--------------------------------------
FDATER is intended for business applications, not historical
ones. FDATER does not take into account historical changes in the
calendar such as the ten days that were dropped from the British
calendar when Britain moved from the Julian to the Gregorian
calendar in the 18th century, or the 11 days that were dropped
from the Russian calendar when Russia made the same move in the
early 20th century. As far as FDATER is concerned, the calendar
has followed the same pattern, unchanged, since January 1, 0001.
======================================================================
FDATER.REX can be called, as an external routine, from any REXX program,
or copied into a REXX program and used as an internal routine.
FDATER takes two parameters, and returns one value.
The first parameter is always the name of one of the FDATER functions,
such as "IsLeapYear" or "MonthName". Parm #1 is NOT case-sensitive.
The second parameter is a string whose contents vary depending on the
function specified in parm #1. The appropriate values for parm #2 are
documented below.
The value that FDATER returns will be as documented below, unless
FDATER.REX detects invalid parameters, in which case it will return a
multi-word message whose first word is "ERROR:"
The .ZIP file that contains FDATER.REX should also contain DRIVER.REX,
which is a short demo program that shows how to call FDATER.REX.
===================================================================
MAIN EXAMPLE:
===================================================================
DueDate = date("B") + 60 /* payment date is 60 days from today */
result = FdateR("Base2Cal", DueDate)
parse var result CalYear CalMonth CalDay .
MonthName = FdateR("Monthname", Calmonth)
DowNum = FdateR("DowNum" , DueDate )
DowName = FdateR("DowName" , Downum )
say "Payment due by" Downame"," Monthname CalDay"," CalYear
===================================================================
===================================================================
DOCUMENTATION FOR EACH OF FDATER'S FUNCTIONS
===================================================================
---------------------------------------------------------------
Function: Convert a base date into a calendar date
Parm #1 : "Base2Cal"
Parm #2 : the number of the base date
Returns : a single string containing
a calendar date in the form "CalYear CalMonth CalDay"
with the three date-parts separated by a space.
EXAMPLE : See MAIN EXAMPLE (above)
---------------------------------------------------------------
Function: Convert a calendar date into a base date
Parm #1 : "Cal2Base"
Parm #2 : a single string containing
a calendar date in the form "CalYear CalMonth CalDay"
with the three date-parts separated by space(s).
Returns : the number of the base date
EXAMPLE :
/* break today's date apart into 3 separate parts */
StandardDate = date("S")
CalYear = substr(StandardDate,1,4)
CalMonth = substr(StandardDate,5,2)
CalDay = substr(StandardDate,7,2)
BaseDate = FdateR("Cal2Base", CalYear CalMonth CalDay)
say "FdateR figures today's base date is:" BaseDate
say "REXX's DATE function base date is:" date("B")
FOR ANOTHER EXAMPLE, SEE THE DRIVER.REX DEMO PROGRAM.
---------------------------------------------------------------
Function: tell whether a year is or is not a leap year
Parm #1 : "IsLeapYear"
Parm #2 : a number indicating a year, from 1 to 9999
Returns : 1 if the year IS a leapyear
0 if the year IS NOT a leapyear
EXAMPLE :
CalYear = "1995"
IsLeapYear = FdateR("IsLeapYear", CalYear)
if IsLeapYear then say CalYear "is a leap year"
else say CalYear "is NOT a leap year"
---------------------------------------------------------------
Function: Calculate the day of the week from the absolute date
Parm #1 : "DowNum"
Parm #2 : a number indicating an absolute date
Returns : the number of the day of the week of that date
1 = Sunday ... 7 = Saturday
EXAMPLE : See MAIN EXAMPLE (above)
---------------------------------------------------------------
Function: Calculate English-language name of the month
Parm #1 : "MonthName"
Parm #2 : the number of the month (1-12, where 1 = January)
Returns : the number of the day of the week of that date
EXAMPLE : See MAIN EXAMPLE (above)
---------------------------------------------------------------
Function: Calculate English-language name of the day of the week
Parm #1 : "DowName"
Parm #2 : the number of the day (1-7, where 1 = Sunday)
Returns : the number of the day of the week of that date
EXAMPLE : See MAIN EXAMPLE (above)
===================================================================
A TIP:
===================================================================
When converting a date from calendar format to base format, FDATER will
quite happily accept some invalid calendar dates (such as Sep 31) and
convert them to a valid base date. If FDATER is then used to convert
that base date back to a calendar date, it will of course convert it to
a valid calendar date (in this case, Oct 1). So one use for FDATER is
to check the validity of a calendar date by converting it to a base date
and then converting the base date back to a calendar date. If you got
the same thing you started with, then the date is valid.