Time display of TAxis got broken after switching to the daylight savings time


I have been using in my application a TGraph with the X-axis set to the time display mode for a long time. I use UTC seconds as X values of the graph points and by default the graph was correctly displaying X labels in local time until the last week-end switch to the daylight savings time. Since than the time labels are behind the actual local time (I’m located in Geneva) by 1 hour.
The problem can be reproduced with the script that is attached at the end of this message. Uncommenting the SetTimeOffset function call makes it working properly. Given this it’s not clear for me what is the default value for the time offset, as without setting it explicitly the time labels are neither “local” (they are behind Geneva time by 1 hour) nor UTC (they are ahead of UTC time by 1 hour). So what is the default? I don’t want to spend too much time to prove this, but I have an impression that a couple of years ago this problem did not exist.

#include <sys/time.h>
void timeaxis()
  TGraph *gr = new TGraph();
  timeval tv;
  gettimeofday(&tv, 0);

  gr->SetPoint(0, tv.tv_sec, 0);
  gr->SetPoint(1, tv.tv_sec + 3600, 1);
  gr->SetPoint(2, tv.tv_sec + 7200, 2);
  gr->SetPoint(3, tv.tv_sec + 10800, 3);
//  gr->GetXaxis()->SetTimeOffset(0, "local");

_ROOT Version: 6.24.06
_Platform: CentOS 7
_Compiler: gcc 11

Yes this part of code is working for a long time now and has not changed since many years. I will have a look at you code.

To ensure the stability of that code we made this macro. It is run each time the doc is build. as you can see all the Expected value and the TGaxis value are the same.

I would recommend you explicitly set the time offset

I would recommend you explicitly set the time offset

Indeed, this is what I’m going to do. But it is still seems to me that something is not done correctly by default. The point is that without explicitly setting time offset, everything worked correctly before switching to the daylight savings but after the switch the time labels get broken.

In all the examples we have the TimeOffset is set to 0. There is no “default”. I know we just have a daylight saving change but that is not the first time since this code was last changed. As I said there was no alert the previous years in both ways: summer-> winter and winter->summer. The next challenge will be when the daylight saving time will be suppressed, if ever.

In all the examples we have the TimeOffset is set to 0. There is no “default”.

I understand that in your examples you are always setting the TimeOffset. But I’m wondering what happens if TimeOffset is not set explicitly. This is what I call “default”, and in this sense this “default” always exists unless you forcibly deprecate any usage of time format for TAxis without setting the TimeOffset. If for example an exception is thrown or an error code is produced if someone tries to use TAxis in Time mode without setting TimeOffset, then I would agree with you - there will be no “default” in this case. But as the feature works without setting TimeOffset, it must be using some “default” and this “default” shall be strictly defined.

I will investigate your example and see what we can do. I kind of agree that “0” should be the “default”. What I am saying is that this code has not changed since many years and therefore many daylight changes.
Thanks for your code. I am looking what can be done.

As said here the default time offset is defined here since the beginning of ROOT.
You can retrieve it with:

root [0] printf("Default time offset = %d\n",(int)gStyle->GetTimeOffset());
Default time offset = 788918400

This value correspond to the beginning of ROOT. It is 1995-01-01. So it is not 0.

When the time offset is not 0, it is used as explained here:

The time axis will spread around the time offset value. Actually it will go from TimeOffset+wmin to TimeOffset+wmax where wmin and wmax are the minimum and maximum values (in seconds) of the axis.

So in that case, by definition, there is no summer or winter time consideration.
When the time offset is 0 the time start at 1970-01-01 (Unix definition) and the summer/winter times apply.

It is difficult to change the time offset default value to 0 as it is equal to 788918400 since the beginning of ROOT.

Thank you for the clear explanation. This is exactly what I wanted to know. It turns out that the wrong time labels in my application went unnoticed for many years.

It could be. I was also thinking that you may have had the global setting with gStyle in your rootlogon.C (or equivalent)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.