Caleçon is both a calculator and a converter of measurement
units. While converting Caleçon's code to Free Pascal, I was pleased to find
that its run time library contains Delphi compatible units convutils
and stdconvs. Unfortunately, both units contain a few
errors. Initially, I opted to write my own conversion unit. Lately, I have
decided to attempt to fix the Free Pascal code and hope to eventually submit
these corrections for inclusion in a future version of the compiler.
The most obvious problem was that conversion between temperatures measured in Celsius and Fahrenheit were incorrect. Other conversions were missing and a couple were wrong.
It turned out that the interface part of the original file had the correct structures to handle non linear conversions such as between degrees Celsius and Fahrenheit but they were not used in the implementation part. Accordingly the implementation part is much changed. I also added some procedures and functions found in recent versions of the Delphi units.
The archive
rtl-conversion.zip contains the projected changes to convutils
and stdconvs along with two demonstration programs and
unit tests. To avoid problems with the original RTL files, the new files are
named mdconvutils.pp, its include file mdconvutil.inc
and mdstdconvs.pp. The unit tests do not cover the
conversion routines in mdstdconvs.pp.
The conversion between TDateTime and Julian dates and
modified Julian dates does not work. After some experimentation, I
ascertained that the problem was in two routines, DateTimeToJulianDate
TryJulianDateToDateTime, found in the dateutils
unit. Turns out that the conversion is done for days, excluding any
fractions of a day. I have raised a ticket in the Free Pascal
bugtracker and hopefully a correction will be applied shortly.
In the meantime, the errors can be seen by comparing the results
obtained with dateconversion (download the archive dateconversion.zip) with
those from a reputable conversion site such as
NASA's Goddard Space Flight Center. If the checkbox Use corrected
functions is checked then functions with my proposed corrections will
be used instead of those in dateutils.