Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dhir_vl
Reel Rookie

Timestamp delta during conversion

I have a response from server which should look like below.

{ "startDate": 1695034800, "endDate": 1695036540 }

 

However, the response is print as below in the console. 

{"startDate":1.6950348e+09,"endDate":1.69503654e+09}

 

I convert the printed startDate to a variable as below.

timestamp& = json.startDate

 

Here, I get incorrect value 1695034752, when it should have been 1695034800. How do I get the correct value? 

 

0 Kudos
4 REPLIES 4
renojim
Community Streaming Expert

Re: Timestamp delta during conversion

I think you need to figure out why the server is returning a floating point number.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
dhir_vl
Reel Rookie

Re: Timestamp delta during conversion

Server is sending long int values as below. I see this in the postman.
{ "startDate": 1695034800, "endDate": 1695036540 }

0 Kudos
renojim
Community Streaming Expert

Re: Timestamp delta during conversion

It works for me:

x="{ "+chr(34)+"startDate"+chr(34)+": 1695034800, "+chr(34)+"endDate"+chr(34)+": 1695036540 }"
?x
{ "startDate": 1695034800, "endDate": 1695036540 }
?parsejson(x)
<Component: roAssociativeArray> =
{
    endDate: 1695036540
    startDate: 1695034800
}
?parsejson(x).enddate
 1695036540
?parsejson(x).startdate
 1695034800
?parsejson(x).enddate - parsejson(x).startdate
 1740
json=parsejson(x)
startdate&=json.startdate
enddate&=json.enddate
?startdate&
 1695034800
?enddate&
 1695036540
?enddate&-startdate&
 1740

The numbers are just Integers, so no need really for the LongIntegers, but it doesn't affect anything.

I don't understand where the floating point numbers are entering the situation.  Maybe post your code.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
dhir_vl
Reel Rookie

Re: Timestamp delta during conversion

Thank you for trying. 

The floating point are entering from the roUrlTransfer. When I get the string from the msg object of the listening port, it is printed as floating point. Additionally when I just copy the floating point into epoch converter, I get the correct value. It's Roku which is not able to parse it. 

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.