variable increase based on passing time using server

Hey guys,

Need some help.

Here’s what I have:

My server is set, accessing and splitting the string is all good for date and time. Here’s my problem.

I am successfully saving the end time of the app as well as the new start time. I’m trying to find the difference between the two times to decide how much to reward the payer.

Here’s the problem, no matter how I try the math I will always have the problem that at midnight the number will go negative. here’s an example

at 12:05:59 we close, cool

at 01:05:34 we start (it actually reads 13:05:34) still good since the second number is obviously larger than the first.

The problem is if i have any time before midnight that I close the game and then open it after that

So close game at 23:59:59 then open at 08:15:59

even those roughly 8 hours has passed the equation will throw a negative instead of a positive. The problem occurs even if i incoporate the date just in different ways

Well, you ignored the days that have passed completely. Since you use your custom time from your server it’s not clear what you actually receive from your server so we can’t suggest a fix. However you generally have to include the date as well as the time (which in computer science is generally called a DateTime value). When you include the date in your calculations the issue should go away. Actually the DateTime struct already can calculate time differences. If you have your date / time values as seperate values you can simply initialize a DateTime value with them.

Keep in mind that using an external time server is pretty pointless if you don’t use https with an actual valid certificate. Otherwise it’s equally simple to spoof the time you get from your server. An additional symmetric encryption and checksum would help as well, though that’s up to you.