[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

460.0. "Date arithmetic" by CSC32::M_BAKER () Mon May 04 1987 23:18

    I need a sure-fire, never-fail algorithm to determine whether or not
    a given year is a leap year.  I'm trying to compute the elapsed time
    between two dates in years, days, hours, minutes, etc.  Can anybody
    help?  I've read up on the definition of a leap year but I'm having
    trouble implementing an algorithm that doesn't break down some where
    along the way.  This is not for work but for my own personal 
    edification.

    Thanks,
    Mike
T.RTitleUserPersonal
Name
DateLines
460.1is this too simple to work?CSC32::M_AMBERMon May 04 1987 23:246
    Is there something wrong with:
    
    If mod(year/4)=0 then leap_year=true
    
    It seems to work fine for me for all (?) dates in our current
    calandar system.
460.2Yes, it's too simple to workCAFEIN::PFAUNow where did I leave my marbles?Tue May 05 1987 00:1215
    It's not that simple.
    
    If mod(year,4)=0 then leap_year = true
    	*UNLESS*
    mod(year,100)=0 in which case, leap_year = false
    	*UNLESS*
    mod(year,400)=0 in which case, leap_year = true again.
    
    To sum it all up, if the year is divisible by 4, it's a leap year
    unless it's a century year in which case it's only a leap year if
    the century is divisible by 4.
    
    Clear as mud?
    
    tom_p
460.3ALBANY::KOZAKIEWICZYou can call me Al...Tue May 05 1987 01:1816
>I'm trying to compute the elapsed time
>between two dates in years, days, hours, minutes, etc.  


Are these VMS absolute dates?  I found out empirically the difference
between the storage formats of absolute and delta times.  The absolute
time is just like it says in the book, i.e. an unsigned quadword containing
the number of 100 nanaosecond intervals since November 17, 1858 (or 
whatever is is...).  Delta times are the ones complemnent of an absolute
time.  For example, "1 12:00:00.00" is the ones complement of
"18-NOV-1858 12:00:00.00".  I have written a couple of routines in 
MACRO, callable from FORTRAN, which do things like subtract absolute
dates to yield a delta time, subtract a delta time from an absolute
time to yield an absolute time, and functions for the comparisons
of VMS dates (LT, LE, GT, GE).  I will post them here if there is an
interest.
460.4A nit: 2's complement, not 1'sDELNI::CANTORDave C.Tue May 05 1987 02:5411
      Re .3
      
      Delta times are ones [sic] complements for absolute times,
      but not in the way you mean.  In the way you mean, they are
      two's complements, in other words, the algebraic negatives
      (additive inverses).   "1 12:00:00.00" is the negative (not
      the complement) of "18-NOV-1858 12:00:00.00".   Were that not
      so, then a quadword of all one-bits would be a zero delta time
      rather then a delta of .000000100 seconds.
      
      Dave C.
460.5PASTIS::MONAHANTue May 05 1987 04:209
    	What range of dates are you considering? The previous replies
    give the rules for from about a couple of hundred years ago to the
    resonably forseeable future.
    
    	Before that, they used different rules for leap years, and as
    a result had a cumulative error. The rules were changed and the
    adjustment for the cumulative error was made in different countries
    at different times. So if you want to handle older dates, your
    algorithm becomes more complex again, and becomes country dependant.
460.6Did I hear someone say "country-specific?"MAY20::MINOWI need a vacationTue May 05 1987 16:177
For more information than you want (or need), feel free to copy
BOLT::DECUSC$LIBRARY:[TOOLS]CALEND.C.

It might also be in the toolshed.

Martin.

460.7ThanksCSC32::M_BAKERWed May 06 1987 17:124
    Many thanks to those who responded here and via mail.  I think I
    have what I need now.  This date stuff can get real tricky sometimes.

    Mike
460.8Stan said it bestDELNI::GOLDSTEINThis Spot Intentionally Mel BlancThu May 07 1987 19:501
    see 216.13!