Question

I am trying to create a mobile app using PhoneGap. I need app to work in disconnected mode. So I am storing data locally and when connection becomes online I sync it with remote data. To perform remote sync I need to pass lastmodified date to the server so it knows which updates to push to the client. The problem is that server time and client times are different. The point of truth is server date, so I need to be able to interpret client date somehow on the server to be in-line with server date or pass server mathcing date from a client. Any suggestions on how to do it? I was thinking of using

(new Date()).getTimezoneOffset() 

from javascript and adjusting client date based on that. But that has issues with day light savings. Any suggestions? Server is an ASP.NET MVC 4 site

Was it helpful?

Solution

If there are multiple clients operating on many time zones, one trick that you can do is to calculate the time difference between the server and the client and apply it when querying the server. Following is are the steps

  1. Client downloads data from the server at 10am (as at the client)
  2. Client stores the last downloaded time
  3. Client goes offline
  4. Client comes online at 1.30pm and decides now is a good time to sync with the server
  5. Client asks for the current time from the server and the server replies its 2.45pm
  6. Now the client knows the time difference between it and the server is 1hr and 15mins
  7. Client applies this delta of 1hr and 15mins to last download time (step 2) and asks the server to send any update since 11.15am server time

Please keep in mind that you have to calculate an apply delta for each transaction (sync operation) as the client may cross time zones during two sync operations

There may be other cool solutions, but this is what comes to mind as a simple solution.

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top