1

UPDATE 2

I've found these but they rely on lat long. Is there any service which can give me result using time zone only as a parameter.

http://www.geonames.org/export/web-services.html#timezone

http://worldtime.io/api/geo


UPDATE 1

I am not using any server. The data is stored in SQLite.


I am creating a health app for Windows Phone 8. In which, user should be allowed to enter certain data on daily basis. So once user has added data for today's date then he/she can enter data on next day only. First I thought to save the last valid date in isolated storage and compare it to current date. If the difference is greater than 24 hours, user should be allowed to enter the data.

Now the problem is if user change the date from his/her phone, DateTime.Now value changes and hence the logic goes wrong. So what should I do to compare the date?

Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115

4 Answers4

1

The last valid date should be decided by the server and not the user. So when the user does an update, you update their last valid date to the current server date, not the user's date. So, before updating, you always compare the user's last valid date (i.e. the server date the last time they updated) to the current server date and see if they're less than 24 hours apart.

Hamza Kubba
  • 2,259
  • 14
  • 12
1

Do the validation on both server and client side. Server side validation is must in this case but it is better to have client side validation to reduce unnecessary server calls.

Damith
  • 62,401
  • 13
  • 102
  • 153
1

If the user is online get the time and date from an online service

How to Query an NTP Server using C#

or this: C#: Get NIST Internet Time

 // Convert it to the current timezone if desired
    date = date.ToLocalTime(); 

National Institute of Standards and Technology (NIST) is the institution that maintains the clocks and makes the time available using Network Time Protocol (NTP). So NIST is the clock and NTP is the manner and method of distributing the time via internet

Community
  • 1
  • 1
D_Bester
  • 5,723
  • 5
  • 35
  • 77
0

If your database is stored on the users device and doesn't use any network connection to some kind of server you simply have to trust your users.

Simply take DateTime.UtcNow.Today for storing the date when the user enters his data. Don't take DateTime.Now or DateTime.UtcNow and check if already 24 hours are gone. In that second case the user won't be able to enter the data at the first day at 11am and the next day at 10am.

Also i would think about not to prohibit entering the data more than once per day. Maybe you should present a message to the users that he already entered some data today and allow him to change the already given data.

If the user really likes to fake some data by changing the datetime of his device, than simply let it do him. If the application works completely locally without any server he only cheats himself.

Oliver
  • 43,366
  • 8
  • 94
  • 151