EncodeDate Rounding issue

Issue #65 resolved
markus_ja created an issue

Hello,

Encoding a data returns wrong value (=rounding issue).

procedure Test;
var
  d, d2: TDate;
  isE: Boolean;
begin
  d := Date;
  d2 := EncodeDate(YearOf(d),MonthOf(d),DAyOf(d));

  isE := d=d2;
  WriteLn(Format('Equal: %s, d: %d, d2: %d', [isE.ToString,d,d2]));

end;

Result:

Equal: False, d: 42557, d2: 42556.91666666667  [line #352]

Comments (5)

  1. Eric Grange repo owner

    Which language/platform is this test intended for?

    AFAICT it does not compile in DWScript (different function names), and in Delphi it would not hit the DWScript date functions.

  2. Eric Grange repo owner

    Time and Date are in UTC, I guess what you are seeing is that the TZ mode for EncodeDate is Local, so you end up with a delta of the timezone offset.

    If so adding DateTimeZone.UTC as last parameter of EncodeDate should give you the same value

  3. Log in to comment