Jump to content
Sign in to follow this  
mausmb

Delphi 10.3 TTimeSpan.GetScaledInterval Android

Recommended Posts

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 by Sherlock
Please consider using the code tags

Share this post


Link to post

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
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;

 

 

Delphi103_timespanAndroid.png.cab4d9320e3556870d19e9b66b9660a5.png

Regards,

marjan 

Edited by mausmb

Share this post


Link to post

Solved   with Frac  ! 

 

wsInvoice.TimeTransaction.AsUTCDateTime:=Frac(tblInovicesTimeTransaction.AsDateTime)

 

br,

Marjan 

Edited by mausmb

Share this post


Link to post
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×