Recent

Author Topic: [SOLVED] IncMinute after 1800 iteration  (Read 1862 times)

jimbill

  • New Member
  • *
  • Posts: 11
[SOLVED] IncMinute after 1800 iteration
« on: November 19, 2017, 05:08:41 pm »
Hello Everyone,

I cant speak very well english  :)

Lazarus is very good tool.
Congratulations to the developers. And so forth

I would like to announce a behaviour of IncMinute function with thousands of iteration.

If I increment a myDate (:TDateTime) by five minutes (iteration 1 to1800) its doing the incrementation well but after 1791th it's incrementing only 4:59 minutes...
Why do this? Is it expected or not?

.
.
.
1789. 2017.11.25. 5:00:00
1790. 2017.11.25. 5:05:00
1791. 2017.11.25. 5:10:00
1792. 2017.11.25. 5:14:59
1793. 2017.11.25. 5:19:59
1794. 2017.11.25. 5:24:59
1795. 2017.11.25. 5:29:59
1796. 2017.11.25. 5:34:59
1797. 2017.11.25. 5:39:59
1798. 2017.11.25. 5:44:59
1799. 2017.11.25. 5:49:59
1800. 2017.11.25. 5:54:59

I'am attaching the source code.


windows 7/32 bit  i386-win32-win32/win64

Any help welcome :).

Thanks

« Last Edit: November 19, 2017, 06:12:07 pm by kirkjake »

Hartmut

  • Hero Member
  • *****
  • Posts: 749
Re: IncMinute after 1800 iteration
« Reply #1 on: November 19, 2017, 05:53:14 pm »
I think this comes because of an accumulated rounding error. Type 'TDateTime' is a double number. For 5 Minutes you always add 5/1440 = 0.0034722...
Try the following, it avoids rounding errors:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.  HH,MMI,SS,MS: Word;
  4.  YY,MM,DD : Word;
  5.  myDate,myDate2:TDateTime;
  6.  i:integer;
  7. begin
  8.   DecodeDate(Date,YY,MM,DD);
  9.   myDate := EncodeDateTime(YY, MM, DD, 0, 0, 0, 0);
  10.  
  11.   for i := 1 to 1800 do  begin
  12.    myDate2:=IncMinute(myDate,(i-1)*5);
  13.    Memo1.Lines.Add(IntToStr(i)+'. '+DateTimeToStr(myDate2));
  14.    Application.ProcessMessages;
  15.   end;
  16. end;  
« Last Edit: November 19, 2017, 05:55:38 pm by Hartmut »

jimbill

  • New Member
  • *
  • Posts: 11
Re: IncMinute after 1800 iteration
« Reply #2 on: November 19, 2017, 06:11:52 pm »
Thanks a lot. :)

It's working.

 

TinyPortal © 2005-2018