Time reference for giving daily tasks online

hi;

I am having problems with giving daily quests in the game I am about to finish. Normally I used to get my time reference from the “worldtimeapi.org” website. But later I realized that I could not access that website from my country and I doubted its reliability in general. It had been very stable for about 2 months.

Daily quests can be set according to the time of the device used, but I know that this is very open to manipulation.

I have no problem with the location, I just want the daily quests to come daily in a stable way. What I am wondering is, does Unity or Google have any support for this that I do not know about? I just want the date for the daily quests.

You always need to maintain a list of fallback domains to get the time from. One website can always go down temporarily or forever or not work for everyone around the globe.

The app should be able to get time from at least half a dozen sites. Ideally locate, test and use 2-3 time site urls per continent / region (more than continents ie southeast asia due to being mostly islands is commonly treated separately from mainland asia). This is assuming the app is for worldwide use, in that case maintaining 20+ URLs would be highly recommended!

1 Like

This is a really good idea. For some reason, I hadn’t thought that I could get time information from more than one site. I’ve tried 4 different sites so far and one of them provided the signal. My daily tasks worked. I want to get into this business with more sites now.
But I have a different question about this subject. I get the date information by writing the location in the code I entered.

For example: https://timeapi.io/api/time/current/zone?timeZone=Europe%2FAmsterdam;

Would specifying this location create any problems other than the different update times for the Far East countries you mentioned? For example, while the daily mission update is exactly 00:00 in Amsterdam, I think that it will not be a big problem for my game if it is 08:00 in Japan.

To elaborate, the code I used is as follows:

public string urlDate= "https://timeapi.io/api/time/current/zone?timeZone=Europe%2FAmsterdam";
public string urlDate_1= "http://worldtimeapi.org/api/timezone/Europe/London";
    public string sDate= "";

using (UnityWebRequest webRequest = UnityWebRequest.Get(urlDate))
        {
            yield return webRequest.SendWebRequest();
            if (webRequest.result== UnityWebRequest.Result.Success)
            {
               
                 string[] splitDate = webRequest.downloadHandler.text.Split(new string[] { "datetime\":\"" }, StringSplitOptions.None);
                  sDate = splitDate[1].Substring(0, 10);            
                Debug.Log("connection success");
            }
            else
            {
                Debug.Log("connection failed amsterdam");
                using UnityWebRequest webRequest_1 = UnityWebRequest.Get(urlDate_1);
                yield return webRequest_1.SendWebRequest();
                if (webRequest_1.result == UnityWebRequest.Result.Success)
                {

                    string[] splitDate = webRequest_1.downloadHandler.text.Split(new string[] { "datetime\":\"" }, StringSplitOptions.None);
                    sDate = splitDate[1].Substring(0, 10);
                    //  sDate = webRequest.downloadHandler.text;
                   
                    Debug.Log("connection success");
                }
 Debug.Log(sDate);

If I am wrong, I would be very happy if you could warn me.

Thank you again for your advice.

I haven’t had to use time services but I’d definitely check that they provide UTC time or Internet Time or any other time that is globally the same and can be offset locally if necessary by the use of the DateTime class. You can init a DateTime instance with a UTC time.

I would definitely avoid doing the string.Split(…).Substring(0,10) as you currently have it, because that’s a hack and who knows when or why there may be a date with 11+ characters. There may be no guarantees as to what the value will be and whether it needs cultural conversion when reading the string value in. The text looks like json so use a JsonUtility (literally if it works, otherwise one of the replacements) to deserialize it into an object with a DateTime field.

1 Like

Also, if you’re already using CloudCode or other such services, you can rely on that.