#include #include #include #include #include "TString.h" #include "TError.h" TString fTimeFormat="%d/%m/%y%F2023-08-16 12:02:57s0"; long long 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; std::tm tm = {}; std::stringstream ss(stime.Data()); // this works in script mode, but not in ACLiC, which is blind to get_time function: // error: no member named 'get_time' in namespace 'std' // ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S"); if(!strptime(stime.Data(), "%Y-%m-%d %H:%M:%S", &tm)) { // not working at some systems Error("GetGMTimeOffset","failed to parse time!"); return 0; } std::time_t time = std::mktime(&tm) // Convert to time_t local time, unixtime ,localOffset = time - std::mktime(std::gmtime(&time)) // local offset, sec ,gmt_time = time - localOffset; // GMT (UTC) unixtim // Info("GetGMTimeOffset","Unix local time=%ld, time zone offset=%ld, unix GMT time=%ld",time,localOffset,gmt_time); return static_cast(gmt_time); } //GetGMTimeOffset int TAxis_GetGMTimeOffset() { long long unix_time = GetGMTimeOffset(); Info("TAxis_GetGMTimeOffset","String format='%s', Unix time (GMT): %lld",fTimeFormat.Data(),unix_time); return 0; }