[Tutor] help with dates

Karl Pflästerer sigurd@12move.de
Tue Jul 29 15:53:01 2003


On 29 Jul 2003, james middendorff <- james2dope@yahoo.com wrote:

> I am attempting to write a little program that will
> tell you on which day a certain holiday will fall. In
> whatever year you want. I am a beginner and was
> wondering how I should tackle this project, or is
> someone could point my in the right direction? Thanks

You could define some fixed date as zero and make all computations with
regard to that date.  Depending on your needs your resolution could be
days or seconds (eg. in Unix day zero is 01.01.1970).  Then you need a
formula to compute leap years; in C that could be (from RFC3339)
,----
|    Here is a sample C subroutine to calculate if a year is a leap year:
| 
|    /* This returns non-zero if year is a leap year.  Must use 4 digit
|       year.
|     */
|    int leap_year(int year)
|    {
|        return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
|    }
`----

After the computation you transfer the days or seconds back to a date.

Leap seconds can't be computed but must be looked up in a table.

,----[ rfc3339 ]
|    The following table is an excerpt from the table maintained by the
|    United States Naval Observatory.  The source data is located at:
| 
|       <ftp://maia.usno.navy.mil/ser7/tai-utc.dat>
|    This table shows the date of the leap second, and the difference
|    between the time standard TAI (which isn't adjusted by leap seconds)
|    and UTC after that leap second.
| 
|    UTC Date  TAI - UTC After Leap Second
|    --------  ---------------------------
|    1972-06-30     11
|    1972-12-31     12
|    1973-12-31     13
|    1974-12-31     14
|    1975-12-31     15
|    1976-12-31     16
|    1977-12-31     17
|    1978-12-31     18
|    1979-12-31     19
|    1981-06-30     20
|    1982-06-30     21
|    1983-06-30     22
|    1985-06-30     23
|    1987-12-31     24
|    1989-12-31     25
|    1990-12-31     26
|    1992-06-30     27
|    1993-06-30     28
|    1994-06-30     29
|    1995-12-31     30
|    1997-06-30     31
|    1998-12-31     32
`----



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list