[net.unix] Adding Time and Date

Cherry.XSIS@xerox.arpa (08/26/86)

I am running Unify under Unix System 5 and I have run into a bit of a problem...

The data which is of our primary concern is time and date.  Unfortunately, Unify
does not offer the capability to perform simple math on times/dates in such a
manner that they will automatically carry or borrow in the proper manner so that
I do not get 45 days per month or 56 hours per day.

Does anybody have a C program or algorithm or formula which can assist me.  I
have written a few test programs but, they fail when the times exceed one year
and I must admit I'm stuck.

Any help would be appreciated.

B.C. & Zot

lcc.jbrown@ucla-locus.arpa (Jordan Brown) (08/27/86)

Use ACM algorithm #199 "Conversions Between Calendar Date and
Julain Day Number".  Once you've converted the dates into julian
days (number of days since the founding of Rome, for trivia buffs)
the arithmetic is trivial.  When done, you convert back.

The algorithms are fairly short; I can type them in if you don't
have the Collected Algorithms available.

bhoward@funvax.UUCP (Bruce Howard) (08/30/86)

> Use ACM algorithm #199 "Conversions Between Calendar Date and
> Julain Day Number".  Once you've converted the dates into julian
> days (number of days since the founding of Rome, for trivia buffs)
> the arithmetic is trivial.  When done, you convert back.
> 
> The algorithms are fairly short; I can type them in if you don't
> have the Collected Algorithms available.

Is there also a simple routine that will allow me to calculate
what day of the week an arbitrary date falls on?

			Bruce

-- 

		 ---------------------------------
...decvax!ittatc!funvax!bhoward  Bruce Howard @ Fairfield University
...ihnp4!itivax!funvax!bhoward   Located in Scenic Fairfield, CT 06430
		 ---------------------------------

hoffman@hdsvx1.UUCP (09/04/86)

> Is there also a simple routine that will allow me to calculate
> what day of the week an arbitrary date falls on?
> 
> 			Bruce

Real simple.  Just take any day as a reference point, note its Julian
Day and the day of the week on which it fell.  To find the day of the
week for some other day, take the difference between the two Julian
Days, mod 7.
-- 
 Richard Hoffman                | "Oh life is a wonderful cycle of song,
 Schlumberger Well Services     |     A medley of extemporanea.
 hoffman%hdsvx1@slb-doll.csnet  | And Love is a thing that can never go wrong
 PO Box 2175, Houston, TX 77252 | ... And I am Marie of Roumania." --D. PARKER

chris@minnie.UUCP (Chris Grevstad) (09/06/86)

lcc.jbrown@ucla-locus.arpa (Jordan Brown) says:
>...
>...
>The algorithms are fairly short; I can type them in if you don't
>have the Collected Algorithms available.

Hmmm... sounds interesting.  Where and how does one get one's hands on this
collection of Collected Algorithms?

--
        Chris Grevstad
        {sdcsvax,hplabs}!sdcrdcf!psivax!nrcvax!chris
        ihnp4!nrcvax!chris

"He cocked his head, asked himself something:  Was death actually preferable
to Los Angeles?  Good question..."

dhb@rayssd.UUCP (David H. Brierley) (09/07/86)

> > Is there also a simple routine that will allow me to calculate
> > what day of the week an arbitrary date falls on?
> > 			Bruce
> Real simple.  Just take any day as a reference point, note its Julian
> Day and the day of the week on which it fell.  To find the day of the
> week for some other day, take the difference between the two Julian
> Days, mod 7.

That's all well and good but you have not addressed the question of
getting the date into Julian in the first place which is not exactly
trivial (although admittedly not very difficult).  What I dont understand
is why no one has suggested using Zeller's congruence?  Is this simple
yet extremely useful algorithm considered second rate?  Or is it just
that no one is familiar with it?  I dont have the source code in front
of me but basically the algorithm takes the month, day of the month,
century, and year of the century and outputs the day of the week.  The
whole thing is only a couple of lines of C code.  If anybody is
interested and doesn't have a reference available with the algorithm
in it, send me mail and I will send you a working version of the algorithm
written in C.
-- 
	Dave Brierley; Raytheon Co.; Portsmouth RI; (401)-847-8000 x4073
	{ allegra, gatech, ihnp4, linus!raybed2 } !rayssd!dhb

psfales@ihlpl.UUCP (Peter Fales) (09/08/86)

> trivial (although admittedly not very difficult).  What I dont understand
> is why no one has suggested using Zeller's congruence?  Is this simple
> yet extremely useful algorithm considered second rate?  Or is it just
> that no one is familiar with it?  I dont have the source code in front
> of me but basically the algorithm takes the month, day of the month,
> century, and year of the century and outputs the day of the week.  The
> whole thing is only a couple of lines of C code.  If anybody is
> interested and doesn't have a reference available with the algorithm
> in it, send me mail and I will send you a working version of the algorithm
> written in C.

Seems like a perfect candidate for posting to the net I'd say!
(or mail me a copy - Thanks)

Peter Fales
...ihnp4!ihlpl!psfales