Calendar math problems
Jaap Spies
j.spies at hccnet.nl
Sun Jan 6 13:13:02 EST 2002
Ben Logan wrote:
> Hi,
>
> I need to be able to add/subtract an arbitrary number of days to/from
> an arbitrary date. The days and dates are all within the range
> 1970-2038, so I thought I would convert everything to Unix time
> stamps, do the addition/subtraction on integers, and convert the
> result back to a date tuple.
>
> Is this the best way to accomplish the task? How would one go about
> it if the dates fall outside the timestamp range? I looked at the
> calendar module functions, and they would be helpful for writing an
> algorithm to do the dirty work, but I don't see any really easy
> solution.
>
> Thanks,
> Ben
>
>
You should use the astronomers trick: translate date/time to Julian Day
(JD): a continuous count of days and fractions thereof since the year
-4712. Do what you want to do and then translate back.
There are various sources on the internet.
Python source: http://astrolabe.sourceforge.net/ see calendar.py:
cal_to_jd() and other usefull algorithms.
Jaap Spies
http://pynovas.sourceforge.net/
More information about the Python-list
mailing list