> =head2 Date Arithmetic
> 
> Date arithmetic has been axed from this proposal. Before you get too
> upset, I had discussions with several people and became convinced that
> this is something too difficult and bloated to stick in core. An
> external module would be much better suited to this. We can still make
> sure this is included with the core distribution.

I understand where you are coming from with this but I could do the date
arithmetic myself if there was a method to return the date from the object
in some generic form. On unix this is seconds from 1970 but the more
generic answer is julian date (or modified julian date). The translation
of date to modified julian date can be done with one formula (plus adding
the fraction of day from the time) [and yes I could put it in a module --
in fact I already have].

The Time::Local module currently has to be used to retrieve time in
seconds from localtime() output.

Adding a "date to MJD (or seconds)" and "MJD (or seconds) to date" method
allows date arithmetic trivially -- this adds code bloat of about 10 lines
to the core but allows the date arithmetic to work.

  $mjd = $date->mjd;

  $mjd += 52.5;   # add 52 days 12 hours to the date

  $date->mjd($mjd);  # or create new date object with this mjd

The MJD to date translation is slightly more complicated but the
algorithms are well known. (Hatcher 1985, Quarterly Journal of the Royal
Astronomical Society, volume 26, page 151).

In summary, adding the functionality of Time::Local to this RFC will make 
date arithmetic possible (although the Time::Local looks to be more
complicated than it should be) without adding undue bloat and
operator overloading. Adding support for (modified) Julian Date
will be much more generic and remove dependency on unix epoch with little
extra code.

Feel free to tell me to use an external module though. I had to mention it
though.

-- 
Tim Jenness
JCMT software engineer/Support scientist
http://www.jach.hawaii.edu/~timj


Reply via email to