I would like to help improving GPC with time and date procedure and functions.
I have been looking into the GPC unit and found this:
{ Is the year a leap year? }
function IsLeapYear (Year : Integer) : Boolean; asmname '_p_is_leap_year';
{ Returns the length of the month, taking leap years into account. }
function MonthLength (Month, Year : Integer) : Integer; asmname '_p_month_length';
Are you calling a c routine(asmname '_p_.......' ) ? if so why if in the unit gpc-bp the function is programmed in pascal?
In gpc-bp unit :
function IsLeapYear (Year : Integer) : Boolean;
begin
IsLeapYear := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0))
end;
function MonthLength (Month, Year : Integer) : Integer;
const
MonthLengths : array [1 .. 12] of Integer =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
if (Month < 1) or (Month > 12)
then MonthLength := 0
else MonthLength := MonthLengths [Month] + Ord ((Month = 2) and IsLeapYear (Year))
end;
If I want to help improve on the date time routines, what would the strategy be to maintain portability?
I think that getting time from the system should be kept in C.
All other calculation on date and time should be done in pascal, in the gpc- or a new datetime-unit, what ever that fits best into maintaining the compiler.
I would like to begin with reorganizing and implementing following:
Is LeapYear (f)
validate date (f)
validate time (f)
calculate day of year (f)
calculate week of year (f)
calculate day of week (f)
calculate standard to business date (year, week, day) (f)
calculate business to standard (f)
validate business date (f)
functions to add/subtract year(s)/month(s)/day(s)/hour(s)/minuet(s)/second(s)
funtion to find difference between to timestamps
When this is done I think of things like this:
formating date/time to strings
decode string to date/time
several languages to day and month names
calculate easter sunday (f)
conversion between gregorian and julian dates and reverse
use julian day number insted of unix_time to make calculations on dates
the airport hours in clik/ticks (1/100) format
ect.
By the way in timestamp definition:
Seconds is 0 .. 61 shoulden it be 0 .. 60 (as 0..59 gives a minuet) and 59 + 1 leap second gives 60?
Hope you can help me begin the right place and that all you other comes with idea's of what to put in a date/time unit as time goes,
klaus