No TAxis::GetTimeOffset() method

Can anyone explain the reason why this method is missing? There is a setter TAxis::SetTimeOffset(), but no getter! When you load two time histograms with two different unknown offsets (T0), how do you do time math with them without knowing T0?

GetTimeFormat() ?

This method returns format how to print date-time values on axis. no any relation to the value of time offset!

It is because there is no TAxis data member storing the time offset passed to SetTimeOffset, It is encoded in the time format. See:

1 Like

Thanks for answer!

Ok, now I see that the offset can be extracted from the time format string by several operations, not quite trivial - filtering the initial string, then converting the string date format to Unix format. Why is it so difficult? What prevents you from saving the offset gmt time in couple of vars (unix secs + millisecs) and returning it to user by TAxis::GetGMTimeOffset()?

The data structure has been defined that way long time ago and a method like GetTimeOffset was not seen as useful at that time, therefore a specific data member was not added. But if you write the code extracting the Time Offset we can put it in the method TAxis::GetTimeOffset and (TGaxis too).

TAxis_GetGMTimeOffset.C (1.6 KB)

BTW I see strange effect with get_time function (see comments in code).
Code runs in script mode, but fails to compile in ACLiC!:

root [0] .x TAxis_GetGMTimeOffset.C
Info in <TAxis_GetGMTimeOffset>: String format='%d/%m/%y%F2023-08-16 12:02:57s0', Unix time (GMT): 1692165777
(int) 0

root [0] .x TAxis_GetGMTimeOffset.C+
Info in <TUnixSystem::ACLiC>: creating shared library /danss/data6/shitov/spk2histo/slow_control_ana/./
In file included from input_line_9:6:
././TAxis_GetGMTimeOffset.C:30:14: error: no member named 'get_time' in namespace 'std'
  ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");

Function strptime is working in both modes, but could be absent on some platforms…

Here is prioROOTized and simplified code using TDatime and skipping most system time libs except correction to local time zone (don’t know how to do this with root functions).

TAxis_GetGMTimeOffset1.C (1.1 KB)

I think we can make the following a TAxis method?

UInt_t GetGMTimeOffset() {

  Int_t idF = fTimeFormat.Index("%F")+2;
  if (idF<2) {
    Warning("GetGMTimeOffset","Time format is not set!");
    return 0;
  TString stime=fTimeFormat(idF,19);
  if (stime.Length() != 19)
    Warning("GetGMTimeOffset","Bad time format!");

  //  Info("GetGMTimeOffset","String format='%s', index=%d, data='%s'",fTimeFormat.Data(),idF,stime.Data());
  //  return 0;

  TDatime datime(stime.Data());

  std::time_t time = datime.Convert()   // Convert to time_t local time, unixtime
    ,localOffset = time - std::mktime(std::gmtime(&time)) // local offset, sec
    ,gmt_time = time - localOffset;     // GMT (UTC) unixtim

  return gmt_time;

yes, it is!

1 Like

TAxis_GetGMTimeOffset2.C (740 Bytes)
Final fully ROOTinazed and simplified version - i have found that GMT conversion is available in TDatime::Convert() method!

@purgenetik1 I made a PR with your code:

Thanks for that !

And sorry for the delay…

PR merged. Thanks again.

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