Inconsistency datime<-> taxis?

Hi,

I have a problem with the following code:

c1 = TCanvas( 'c1', 'canvas', 500, 500)
g = TGraph()

g.SetPoint(0, TDatime("1995-1-1 0:0:0").Convert(), 1)
g.SetPoint(1, TDatime("2000-1-1 0:0:0").Convert(), 2)
g.SetPoint(2, TDatime("2005-1-1 0:0:0").Convert(), 3)

g.Draw("A")

g.GetXaxis()->SetTimeFormat("#splitline{%d/%m/%y}{%H:%M:%S}")
g.GetXaxis()->SetTimeDisplay(1)

g.Draw("A*")

In the resulting plot all dates are shifted by 25 years into the future. So I think the TAxis uses 1995-1-1 as the base for the timestamp. Is this behaviour intended and is there a way to bypass this problem?


Try to set the time offset to 0. See the some examples here:
root.cern.ch/drupal/content/how- … time-units

OK, this worked. Thank you for the hint! But I still think that the different default offsets are confusing.

BTW, I already found the documentation in your posted link when I searched for a solution all by myself. But from that I understood that the offset must be 01-01-1995 or greater. So maybe your hint to set the offset (without the conversion via TDatime as done in all of the examples) could be included somewhere in the documentation?

And I stay with my opinion that it is really confusing that TDatime only accepts dates after 01-01-1995 (why?) but returns seconds since 01-01-1970 which is not the default of TAxis.

Yes, may be this page is too complex. Note that the example at the end of this page an example with offset 0 is shown.

But the last example has no explanations and I originally thought that it was there to illustrate the use of “gmt” and considered an offset of 0 merely as the default. Since the use of Unix time is common I would recommend a short paragraph about its use together with TAxis in the howto to help others struggling with the same issue.

Ok, I’ll revisit that.

Sorry to dig this old thread, but I believe the not so obvious has to be stated explicitely somewhere, so here it is : date in TDatime having to be younger than 1995, gStyle->SetTimeOffset(TDatime(“1970-01-01 0:00:00”).Convert()) won’t work. To set the offset as a date between 1970 and 1995, one has to compute the timestamp outside ROOT (or by whichever other method I’m not aware of), then feed it to gStyle->SetTimeOffset(). That is, gStyle->SetTimeOffset(0) will set the offset such that UNIX timestamps will be correctly displayed.

In the HowTo page it is already said that the date in TDatime should be greater than 1995:

You want this sentence to be completed telling what you wrote concerning dates between 1970 and 1995 ?

I think it could be useful. I believe the most frequent wanted behaviour is a compliance with the standard UNIX timestamp, so at least mentioning that this is obtained by setting the offset as 0 may be a good idea. But anyway, now it is mentioned here and I found the howto thanks to this topic, so do as you want. :slight_smile: