mausmb 13 Posted November 24, 2018 (edited) Hi, Working with time in DB datetime format (example : '30.12.1899 09:18:54') on Android Delphi 10.3 throws exception- sTimespanTooLong. On Windows (and previous Delphi version) is OK. class function TTimeSpan.GetScaledInterval(Value: Double; Scale: Integer): TTimeSpan; var NewVal: Double; begin if IsNan(Value) then raise EArgumentException.Create(sTimespanValueCannotBeNan); NewVal := Value * Scale; if Value >= 0.0 then NewVal := NewVal + 0.5 else NewVal := NewVal - 0.5; if (NewVal > MaxMilliseconds) or (NewVal < MinMilliseconds) then raise EArgumentOutOfRangeException.Create(sTimespanTooLong); Result := TTimeSpan.Create(Trunc(NewVal) * TicksPerMillisecond); end; How to set initial datetime for Android ? WorkAround is simple, but ugly if (NewVal > MaxMilliseconds) then NewVal:=MaxMilliseconds; if (NewVal < MinMilliseconds) then NewVal:=MinMilliseconds; Regards, Marjan Edited November 27, 2018 by Sherlock Please consider using the code tags Share this post Link to post
Stefan Glienke 2002 Posted November 24, 2018 What exactly do you do, what you posted is a private method that obviously gets called from another public method. Please show your code. Share this post Link to post
mausmb 13 Posted November 24, 2018 (edited) 2 hours ago, Stefan Glienke said: What exactly do you do, what you posted is a private method that obviously gets called from another public method. Please show your code. type tblInovices: TFDMemTable; tblInovicesTimeTransaction: TDateTimeField; ... onNewRecord... tblInovicesTimeTransaction.AsDateTime:=Time; afterpost - Prepare data and send it to Web (SOAP) web service if tblInovicesTimeTransaction.Value<>Null then Begin wsInvoice.TimeTransaction:=TXSDateTime.Create; wsInvoice.TimeTransaction.AsUTCDateTime:=tblInovicesTimeTransaction.AsDateTime; // Exception sTimespanTooLong ..traced to Unit System.TimeSpan // same Exception (sTimespanTooLong) Error with AsDateTime // wsInvoice.TimeTransaction.AsDateTime:=tblInovicesTimeTransaction.AsDateTime; End; Regards, marjan Edited November 24, 2018 by mausmb Share this post Link to post
mausmb 13 Posted November 27, 2018 (edited) Solved with Frac ! wsInvoice.TimeTransaction.AsUTCDateTime:=Frac(tblInovicesTimeTransaction.AsDateTime); br, Marjan Edited November 27, 2018 by mausmb Share this post Link to post
David Heffernan 2345 Posted November 27, 2018 52 minutes ago, mausmb said: Solved with Frac ! wsInvoice.TimeTransaction.AsUTCDateTime:=Frac(tblInovicesTimeTransaction.AsDateTime); br, Marjan Doesn't seem like that's a real solution....... Share this post Link to post
mausmb 13 Posted November 28, 2018 On 11/27/2018 at 2:20 PM, David Heffernan said: Doesn't seem like that's a real solution....... It's not just easier override And recurring problem with TXSDateTime "The given "30.12.1899 13:09:05" local time is invalid (situated within the missing period prior to DST" br, Marjan Share this post Link to post