Need clarity on the value returned by TimeCurrent() in MT4 Build 1353

 

One of my scripts stopped working after the update to MT4 v4.00 Build 1353 (16 Dec 2021). This script relies on an accurate value returned by function TimeCurrent(). I conducted a test with the following script on an MT4 platform which uses timezone GMT+2h:

#property strict

void OnStart()
{
        datetime MT4_currentTime = TimeCurrent();
        datetime currentGMT_Time = TimeGMT();
        datetime timeDifference = MT4_currentTime - currentGMT_Time;
        Print("Current Time is: ", MT4_currentTime);   
        Print("Current GMT Time is: ", currentGMT_Time);
        Print("Time Difference between GMT and CurrentTime: ", timeDifference);
}

The result I get is something like:

Time Difference between GMT and CurrentTime: 1970.01.01 02:00:09
Current GMT Time is: 2021.12.20 08:35:23
Current Time is: 2021.12.20 10:35:32

The above result shows that, Current Time is 9s AHEAD of where it should be. IF GMT is 08:35:23, then GMT+2h should be 10:35:23. Why does TimeCurrent() return 10:35:32, which is 9s ahead?

Would someone please fill me in? Why is TimeCurrent 9s ahead? It wasn't this way before in previous builds. I made some posts about this problem in the Build 1353 thread but I was told that this is normal. How can it be normal? GMT+2h should mean EXACTLY GMT+2h, without any discrepancy.
 
shoxie:

One of my scripts stopped working after the update to MT4 v4.00 Build 1353 (16 Dec 2021). This script relies on an accurate value returned by function TimeCurrent(). I conducted a test with the following script on an MT4 platform which uses timezone GMT+2h:

The result I get is something like:

The above result shows that, Current Time is 9s AHEAD of where it should be. IF GMT is 08:35:23, then GMT+2h should be 10:35:23. Why does TimeCurrent() return 10:35:32, which is 9s ahead?

Would someone please fill me in? Why is TimeCurrent 9s ahead? It wasn't this way before in previous builds. I made some posts about this problem in the Build 1353 thread but I was told that this is normal. How can it be normal? GMT+2h should mean EXACTLY GMT+2h, without any discrepancy.

Is your computer time accurate? You may try to synchronize. 

 
Laszlo Tormasi #:

Is your computer time accurate? You may try to synchronize. 

OK. I went to Windows time settings, then turned on "Set Time Zone Automatically" and now I no longer have the issue in MT4. Thanks for your suggestion. Looks like it has nothing to do with Build 1353.

I still don't understand though. Why would the value of TimeCurrent() be dependent on my computer's time? I thought it's an absolute value returned by the broker's server.

 
shoxie #:

OK. I went to Windows time settings, then turned on "Set Time Zone Automatically" and now I no longer have the issue in MT4. Thanks for your suggestion. Looks like it has nothing to do with Build 1353.

I still don't understand though. Why would the value of TimeCurrent() be dependent on my computer's time? I thought it's an absolute value returned by the broker's server.

TimeGMT is based on TimeLocal.

TimeCurrent is always accurate. Problems arise when it is compared to TimeGMT or TimeLocal and the computer clock is out of synch. 

 
  1. Don't double post! You already had another thread open.

              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

  2.         datetime timeDifference = MT4_currentTime - currentGMT_Time;
    The difference between two datetimes is not a datetime, it's an int.
 
Laszlo Tormasi #:

TimeGMT is based on TimeLocal.

TimeCurrent is always accurate. Problems arise when it is compared to TimeGMT or TimeLocal and the computer clock is out of synch. 

Thanks, but that doesn't really help. On my system it was TimeCurrent() that returned an erroneous value. TimeGMT() was fine. Well, now that I can no longer replicate the error we'll never know why. But thanks.


William Roeder #:
  1. Don't double post! You already had another thread open.

              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

  2. The difference between two datetimes is not a datetime, it's an int.

I double-posted here because someone in the other thread asked the moderator to delete my posts because they weren't relevant to Build 1353. I guess I now agree. The problem was on my system from the look of it.

"The difference between two datetimes is not a datetime, it's an int" - Thanks for the clarification.
 
Laszlo Tormasi #: TimeCurrent is always accurate.

Wrong. It is whatever the last server time sent was.

There was a case about ten (10) years ago, where the time was correct, but the date was several days ahead.

When it was corrected, many EAs stopped working for those days because the new bar code used greater or equal (>=) instead of not equal (!=).

 
William Roeder #:

Wrong. It is whatever the last server time sent was.

There was a case about ten (10) years ago, where the time was correct, but the date was several days ahead.

When it was corrected, many EAs stopped working for those days because the new bar code used greater or equal (>=) instead of not equal (!=).

I am sorry, I meant the local computer time does not affect the actual TimeCurrent value.



 
shoxie #:

Thanks, but that doesn't really help. On my system it was TimeCurrent() that returned an erroneous value. TimeGMT() was fine. Well, now that I can no longer replicate the error we'll never know why. But thanks.

You can set wrong time on your computer to reproduce the issue.
 
Laszlo Tormasi #:
You can set wrong time on your computer to reproduce the issue.
Hmm. Thanks. Will look into it... Obviously one of the two functions is susceptible to corruption depending on the local computer's time.