[fpc-devel] Definition of the time-fration in a TDateTime before 30/12/1899

Vincent Snijders vsnijders at quicknet.nl
Mon May 22 16:29:37 CEST 2006


Graeme Geldenhuys schreef:
> On 5/22/06, Florian Klaempfl <florian at freepascal.org> wrote:
>> > Should we convert existing tests to fpcunit ?
>>
>> No, too much work, no real gain :)
> 
> Just curious...
> 
> I have never looked at the tests created in FPC, but how much work
> (lines of code)  would it take to test something like the following
> snippet of our tests we have. (very simple example)  If it isn't to
> much work, the benefits will be huge as fpcUnit has a lot of
> advantages. TestDecorator, Exception testing, XML output, etc...  As I
> said, we use fpcUnit extensively.  Currently running at around 1500+
> unit tests, testing database connections, string utils, threading,
> etc...
> 
> In the example below tiUtils.tiDateTimeAsIntlDateDisp outputs dates in
> the ISO international datetime format.  Most of our test are as easy
> as this, 1 or 2 liners.  Not to mention fpcUnit give you results in
> XML output which we convert to a html page via xslt to be viewer over
> the web to see what the nightly build did.
> 
> procedure TTestTIUtils.tiDateTimeAsIntlDateDisp;
> var
>  dt: TDateTime;
> begin
>  dt := EncodeDate(2006, 1, 18) + EncodeTime(15, 19, 22, 0);
>  CheckEquals('2006-01-18 15:19:22',
> tiUtils.tiDateTimeAsIntlDateDisp(dt), 'Failed on 1');
> 
>  dt := EncodeDate(2002, 1, 02) + EncodeTime(12, 34, 56, 12);
>  CheckEquals('2002-01-02 12:34:56',
> tiUtils.tiDateTimeAsIntlDateDisp(dt), 'Failed on 2');
> 
>  dt := EncodeDate(2006, 1, 18);
>  CheckEquals('2006-01-18 00:00:00',
> tiUtils.tiDateTimeAsIntlDateDisp(dt), 'Failed on 3');
> 
>  dt := EncodeTime(9, 10, 41, 22);
>  CheckEquals('0000-00-00 09:10:41',
> tiUtils.tiDateTimeAsIntlDateDisp(dt), 'Failed on 4');
> 
>  dt := EncodeDateTime(1652, 6, 15, 12, 34, 56, 12);
>  CheckEquals('1652-06-15 12:34:56',
> tiUtils.tiDateTimeAsIntlDateDisp(dt), 'Failed on 5');
> 
> [....]
> end;
> 

In the current framework it would look like this:

program tiDateTimeAsIntlDateDisp;

uses
   tiUtils; // I am guessing it is a unit, but it could be an object too.

var
  dt: TDateTime;
begin

  dt := EncodeDate(2006, 1, 18) + EncodeTime(15, 19, 22, 0);
  if '2006-01-18 15:19:22'<>
    tiUtils.tiDateTimeAsIntlDateDisp(dt) then halt(1);

  dt := EncodeDate(2002, 1, 02) + EncodeTime(12, 34, 56, 12);
  if '2002-01-02 12:34:56' <> tiUtils.tiDateTimeAsIntlDateDisp(dt)
     then halt(2);

  dt := EncodeDate(2006, 1, 18);
  if '2006-01-18 00:00:00'<>tiUtils.tiDateTimeAsIntlDateDisp(dt)
    then halt(3);

  dt := EncodeTime(9, 10, 41, 22);
  if '0000-00-00 09:10:41'<>tiUtils.tiDateTimeAsIntlDateDisp(dt)
    then halt(4);

  dt := EncodeDateTime(1652, 6, 15, 12, 34, 56, 12);
  if '1652-06-15 12:34:56' <> tiUtils.tiDateTimeAsIntlDateDisp(dt)
    then halt(5);

[....]
end.

The results are gathered and published on:
http://www.freepascal.org/cgi-bin/testsuite.cgi

Vincent.





More information about the fpc-devel mailing list