HP3000-L Archives

June 1996, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Michael P. Smith" <[log in to unmask]>
Reply To:
Michael P. Smith
Date:
Wed, 26 Jun 1996 18:18:10 GMT
Content-Type:
text/plain
Parts/Attachments:
text/plain (70 lines)
In article <[log in to unmask]>,
   Stan Sieler <[log in to unmask]> wrote:
[snip]
>
>For example, many people have code that calculates the "day-of-week"
>for a given date ... using an algorithm that breaks down after 1999-12-31.
>(Euler's?)  No line-by-line analysis by a programmer will find that
>problem if they don't know it exists!
 
I don't mean to seem naive, but could someone provide me a copy of Euler's
algorithm.  To be honest, I reinvented the wheel when trying to come up with a
command file that did day of week calculations and came up with the following,
if it is wrong I hope someone will correct me.
 
PARM p1="!hpmonth" p2="!hpdate" p3="19!hpyear"
SETVAR _dow_month ![UPS("!p1")]
SETVAR _dow_day   ![UPS("!p2")]
SETVAR _dow_year  ![LFT("19!hpyear",4-LEN("!p3"))+"!p3"]
SETVAR _dow_days  "Sun   Mon   Tues  WednesThurs Fri   Satur  "
SETVAR _dow_xyear     _dow_year-((12-_dow_month)/10)
SETVAR _dow_xmonth    _dow_month+(((12-_dow_month)/10)*12)
SETVAR _dow_xday      _dow_day+(_dow_xmonth*2)+(((_dow_xmonth+1)*6)/10)
SETVAR _dow_leap_year (_dow_xyear/4) - (_dow_xyear/100) + (_dow_xyear/400)
SETVAR _dow_xday      (_dow_xday+_dow_xyear+_dow_leap_year+1) MOD 7
SETVAR _dow_xdays     STR(_dow_days,_dow_xday*6+1,6)
ECHO Date        = !_dow_month/!_dow_day/!_dow_year
ECHO Day of week = !_dow_xday
ECHO Day name    = ![RTRIM(_dow_xdays)]day
DELETEVAR _dow_@
 
It seems to work.  While we're at it, would someone mind commenting on my day
of
year command file as well?  Here that one is.
 
PARM p1="" p2="" p3="!hpyear"
SETVAR month ![UPS("!p1")]
SETVAR day   ![UPS("!p2")]
SETVAR year  ![LFT("19!hpyear",4-LEN("!p3"))+"!p3"]
SETVAR doy_days ((month-1)*304/10)+((month+2)/10)+(((12-month)/10)*month)
SETVAR doy_ly (1/(1+(year MOD 4)))-(1/(1+(year MOD 100)))
SETVAR doy_ly (doy_ly+(1/(1+(year MOD 400))))*((7+month)/10)
SETVAR doy_days doy_days+doy_ly+(day-1)
ECHO Day of year for !month/!day/!year is !doy_days
DELETEVAR doy_@
 
These are both very old routines (about 7 years if I remember right), and I
think they work, but to be honest, I am not sure how to test them.  To date all
I have done is random sampling testing and they both seem fine, for both the
19xx and 20xx years (I'm not going to bother with 21xx for obvious reasons :))
 
To be honest, I thought about submitting these to Interex, but they seemed so
simple I didn't want to embarrass myself by submitting something this trivial.
 
Any response is welcome, especially if there is Pascal or C code involved.
 
 
-------------------------------------------------------------------
Michael P. Smith                        [log in to unmask]
HP Sr. Systems Programmer               [log in to unmask]
Hertz Corporation, Oklahoma City, OK
-------------------------------------------------------------------
 
Manager: My boss says we need some eunuch programmers
Dilbert: I think he means UNIX and I already know UNIX.
Manager: If the company nurse drops by, tell her I said 'Never mind.'
 
-------------------------------------------------------------------
The views and opinions expressed in this document are expressly
my own.  So get off the couch, I obviously need more help than you.

ATOM RSS1 RSS2