After some close examination of the 'DAYS' command file I posted
earlier this week, and a suggestion by Lars to use a lookup table
instead of an 'IF/ELSEIF' block to count the days in the months so
far this year; I'm posting the new, improved version of 'DAYS'.
Note that the original script erroneously used HPYYYY when checking
the year, and that the calculation for D_YEAR_DAYS handles all leap
years *except* for non-leap centuries (so we don't have to allow for
29 days in Feb. when calculating D_MONTH_DAYS)...
:
:HELP DAYS
USER DEFINED COMMAND FILE: DAYS.XEQ.SYS
PARM D_DATE
# DAYS.XEQ - RETURNS NUMBER OF DAYS SINCE DEC 31, 1899
# D_DATE MUST BE A DATE IN YYYYMMDD FORM.
# TIM ERICSON 07/14/1998
SETVAR D_YEAR, STR ( "!D_DATE", 1, 4 )
SETVAR D_YEAR, !D_YEAR
IF D_YEAR MOD 100 <> 0 &
OR D_YEAR MOD 400 = 0 &
OR D_YEAR = 1900
SETVAR D_YEAR_DAYS, ( ( !D_YEAR - 1900 ) * 1461 ) / 4
ELSE
SETVAR D_YEAR_DAYS, ( ( ( !D_YEAR - 1900 ) * 1461 ) / 4 ) - 1
ENDIF
SETVAR D_MONTH, STR ( "!D_DATE", 5, 2 )
SETVAR D_MONTH, !D_MONTH - 1
SETVAR D_MONTH_DAYS, 0
WHILE D_MONTH > 0 DO
SETVAR D_MONTH_DAYS, D_MONTH_DAYS + &
![ STR ( "312831303130313130313031", ( 2 * D_MONTH ) - 1, 2 ) ]
SETVAR D_MONTH, D_MONTH - 1
ENDWHILE
SETVAR D_DAYS, STR ( "!D_DATE", 7, 2 )
SETVAR D_DAYS, !D_DAYS
SETVAR RETURN_DAYS, D_YEAR_DAYS + D_MONTH_DAYS + D_DAYS
DELETEVAR D_@
:
:
Whew!
+------------------------------------------------------------------+
My mind is my own, as are my ideas and opinions.
My heart, body, and soul, however, all belong to others. Tim.
+------------------------------------------------------------------+
Tim Ericson tericson DenKor Dental Management Corp.
Sr. Programmer/Analyst at denkor 503-526-4440 (direct number)
(& Systems Manager) dot com http://www.denkor.com
Programming HP3000s since 1983!
+------------------------------------------------------------------+
UDCs and Command Files: http://www.denkor.com/hp3000/command_files
+------------------------------------------------------------------+
|