Error in VCLTee.TeeJavaScript

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
WilliE
Newbie
Newbie
Posts: 18
Joined: Mon Nov 30, 2020 12:00 am

Error in VCLTee.TeeJavaScript

Post by WilliE » Mon Mar 28, 2022 12:28 pm

Hello,
there is a problem with Daylight Savings Time in the export of TDatetime values in VCLTee.TeeJavaScript.pas of ver. 2022.34.
In line 1014 happens an ELocalTimeInvalid exception in tmpDate:=TTimeZone.Local.ToUniversalTime(AList[Index])
and therefore the export to JavaScript is wrong. We have an device that is unable to save the date time in the right way and therefore it saves values as "2022-03-27 02:00:10".

function ValueDateTimeToStr(Index:Integer):String;
var tmpDate: TDateTime;
const
Jan1st_1970:TDateTime=25569.0;
begin
if Series.IsNull(Index) then
result:='null'
else
begin
{$IFDEF D15}
tmpDate:=TTimeZone.Local.ToUniversalTime(AList[Index]);
{$ELSE}
tmpDate:=DateTime2UnivDateTime(AList[Index]);
{$ENDIF}
result:='new Date('+IntToStr(Round((tmpDate-Jan1st_1970)*86400000))+')';
end;
end;

there is now problem in the VCL branch of our program with values like "2022-03-27 02:00:10", and the MS SQL Server saves values like "2022-03-27 02:00:10" also without any problem. Only the export to JavaScript has a problem.


your sincerely

Willi

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Error in VCLTee.TeeJavaScript

Post by Marc » Thu Mar 31, 2022 7:37 am

Hello Willi,

Hmmm.... this will need thinking about. UTC may be considered "by design".

In place of

Code: Select all

tmpDate:=TTimeZone.Local.ToUniversalTime(AList[Index]);
You can try the following codeline:

Code: Select all

tmpDate:=TTimeZone.Local.ToLocalTime(AList[Index]);
Is that the result you're looking for?

With thanks.
Regards,
Marc Meumann
Steema Support

WilliE
Newbie
Newbie
Posts: 18
Joined: Mon Nov 30, 2020 12:00 am

Re: Error in VCLTee.TeeJavaScript

Post by WilliE » Thu Mar 31, 2022 12:16 pm

Hello Marc,
with your modification the exception didn't happen. But now all the time values in the javascript export are wrong. E.g. a date time of "31.03.2022 06:00" is converted to "31.03.2022 10:00"

Willi

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Error in VCLTee.TeeJavaScript

Post by Marc » Fri Apr 01, 2022 10:39 am

Hello Willi,

Ok thanks for testing that.

Using the original codeline, (tmpDate:=TTimeZone.Local.ToUniversalTime(AList[Index]);), are you able to break on the line and send tell us a value of AList[Index] that generates the ELocalTimeInvalid exception? ....or, better, if you're able to send us a small sample dataset, enough that we can run in a chart to cause the exception, that would be useful.

Thanks,
Marc
Steema Support

WilliE
Newbie
Newbie
Posts: 18
Joined: Mon Nov 30, 2020 12:00 am

Re: Error in VCLTee.TeeJavaScript

Post by WilliE » Mon Apr 04, 2022 2:23 pm

Hello Marc,
here is a snippet with German datetime coding

Date_in.Text := '27.03.2022 02:01:00';
tmpDate_in := StrToDateTime (Date_in.Text);
tmpDate_out := TTimeZone.Local.ToUniversalTime(tmpDate_in);
Date_out.Text := DateTimeToStr (tmpDate_out);

In 2022 the switch of Daylight Saving Time was on 27/03/2022 at 02h to 3h (local time). Therefore the function TTimeZone.Local.ToUniversalTime is throwing a ELocalTimeInvalid for all values between 01:59:59 to 03:00:00 on 27/03/2022

I think in Spain is the Daylight Saving Time the same as in Germany.

Willi

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Error in VCLTee.TeeJavaScript

Post by Marc » Thu Apr 07, 2022 9:30 pm

Hello Willi,

Yes, so this appears to be a Delphi issue, not related to TeeChart. The daylight changeover time coincides exactly with what would be, thus, an invalid date. If I take your routine and output the result to an edit box:

Code: Select all

procedure TForm1.Button3Click(Sender: TObject);
Var Date_in_Text, Date_out_Text : String;
    tmpDate_in, tmpDate_out : TDateTime;
    FS: TFormatSettings;
begin
  FS := TFormatSettings.Create('en-UK');
  FS.DateSeparator := '.';

  Date_in_Text := '27.03.2022 01:59:00';
  tmpDate_in := StrToDateTime (Date_in_Text,FS);
  tmpDate_out := TTimeZone.Local.ToUniversalTime(tmpDate_in);
  Date_out_Text := DateTimeToStr (tmpDate_out);

  Edit1.Text := Date_out_Text;
end;
This works fine: Date_in_Text := '27.03.2022 01:59:00';
This doesn't: Date_in_Text := '27.03.2022 02:00:00';
This doesn't: Date_in_Text := '27.03.2022 02:59:00';
This does: Date_in_Text := '27.03.2022 03:00:00';
Daylight saving cuts out the whole hour. We could add an invalid date check as in this post:
https://stackoverflow.com/questions/559 ... th-value-0
ie.
if TTimeZone.local.IsInvalidTime(MyDate) then ...change the time to the next 'good' time.

We could look to protect TeeChart code, changing the time on the way in, though perhaps TeeChart would be presumptuous to do so, to take that decision, and perhaps the incoming dates should be checked before arriving at the Chart. We'll consider what action to take.

With thanks.
Regards,
Marc
Steema Support

WilliE
Newbie
Newbie
Posts: 18
Joined: Mon Nov 30, 2020 12:00 am

Re: Error in VCLTee.TeeJavaScript

Post by WilliE » Fri Apr 08, 2022 5:43 pm

Hello Marc,
the workaround is working quite well. If TTimeZone.local.IsInvalidTime it true I have added one hour to the date.

Willi

Post Reply