Skip to content
Snippets Groups Projects
Commit 5c5cc063 authored by Rene Brun's avatar Rene Brun
Browse files

From Olivier:

Implement suggestion from Damir Buskulic:

- Take into account the decimal part of the time offset.
- New parameter "option" in SetTimeOffset. Default value is "local"
  meaning the time offset should be consider as a local time. It can
  be set to "gmt" meaning the time offset should be consider as GMT time.


git-svn-id: http://root.cern.ch/svn/root/trunk@7654 27541ba8-7e3a-0410-8455-c3a389f83636
parent 36c0b370
No related branches found
No related tags found
No related merge requests found
// @(#)root/graf:$Name: $:$Id: TGaxis.h,v 1.13 2003/04/10 09:00:20 brun Exp $
// @(#)root/graf:$Name: $:$Id: TGaxis.h,v 1.14 2003/09/12 09:18:01 brun Exp $
// Author: Rene Brun, Olivier Couet 12/12/94
/*************************************************************************
......@@ -115,7 +115,7 @@ virtual const char *GetTitle() const {return fTitle.Data();}
void SetTickSize(Float_t ticksize) {fTickSize = ticksize;} // *MENU*
void SetGridLength(Float_t gridlength) {fGridLength = gridlength;}
void SetTimeFormat(const char *tformat);
void SetTimeOffset(Double_t toffset);
void SetTimeOffset(Double_t toffset, Option_t *option="local");
virtual void SetTitle(const char *title=""); // *MENU*
void SetTitleOffset(Float_t titleoffset=1) {fTitleOffset = titleoffset;} // *MENU*
void SetTitleSize(Float_t titlesize) {fTitleSize = titlesize;} // *MENU*
......
// @(#)root/graf:$Name: $:$Id: TGaxis.cxx,v 1.59 2003/09/23 14:56:50 brun Exp $
// @(#)root/graf:$Name: $:$Id: TGaxis.cxx,v 1.60 2003/11/25 11:34:58 brun Exp $
// Author: Rene Brun, Olivier Couet 12/12/94
/*************************************************************************
......@@ -622,7 +622,18 @@ void TGaxis::PaintAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t yma
tp.tm_min = mi;
tp.tm_sec = ss;
tp.tm_isdst = -1;
timeoffset = mktime(&tp);
timeoffset = mktime(&tp);
// Add the time offset's decimal part if it is there
Int_t Ids = stringtimeoffset.Index("s");
if (Ids >= 0) {
Float_t dp;
Int_t Lns = stringtimeoffset.Length();
TString sdp = stringtimeoffset(Ids+1,Lns);
sscanf(sdp.Data(),"%g",&dp);
timeoffset += dp;
}
// if OptionTime = 2 gmtime will be used instead of localtime
if (stringtimeoffset.Index("GMT")) OptionTime =2;
} else {
Error(where, "Time offset has not the right format");
}
......@@ -1353,7 +1364,11 @@ L110:
if (OptionTime) {
timed = Wlabel + (int)(timeoffset) - rangeOffset;
timelabel = (time_t)((Long_t)(timed));
utctis = localtime(&timelabel);
if (OptionTime == 1) {
utctis = localtime(&timelabel);
} else {
utctis = gmtime(&timelabel);
}
TString timeformattmp;
if (timeformat.Length() < 220) timeformattmp = timeformat;
else timeformattmp = "#splitline{Format}{too long}";
......@@ -1935,22 +1950,43 @@ void TGaxis::SetTimeFormat(const char *tformat)
}
//______________________________________________________________________________
void TGaxis::SetTimeOffset(Double_t toffset)
void TGaxis::SetTimeOffset(Double_t toffset, Option_t *option)
{
// Change the time offset
char sqldate[20];
// If option = "gmt" the time offset is treated as a GMT time.
TString opt = option;
opt.ToLower();
Bool_t gmt = kFALSE;
if (opt.Contains("gmt")) gmt = kTRUE;
char tmp[20];
time_t timeoff;
struct tm* utctis;
Int_t IdF = fTimeFormat.Index("%F");
if (IdF>=0) fTimeFormat.Remove(IdF);
fTimeFormat.Append("%F");
timeoff = (time_t)((Long_t)(toffset));
utctis = localtime(&timeoff);
if (gmt) {
utctis = gmtime(&timeoff);
} else {
utctis = localtime(&timeoff);
}
strftime(tmp,256,"%Y-%m-%d %H:%M:%S",utctis);
fTimeFormat.Append(tmp);
// append the decimal part of the time offset
Double_t ds = toffset-(Int_t)toffset;
if(ds!= 0) {
sprintf(tmp,"s%g",ds);
fTimeFormat.Append(tmp);
}
strftime(sqldate,256,"%Y-%m-%d %H:%M:%S",utctis);
fTimeFormat.Append(sqldate);
// If the time is GMT, stamp fTimeFormat
if (gmt) fTimeFormat.Append(" GMT");
}
//______________________________________________________________________________
......
// @(#)root/hist:$Name: $:$Id: TAxis.h,v 1.25 2003/04/10 09:00:21 brun Exp $
// @(#)root/hist:$Name: $:$Id: TAxis.h,v 1.26 2003/09/12 09:18:01 brun Exp $
// Author: Rene Brun 12/12/94
/*************************************************************************
......@@ -119,7 +119,7 @@ public:
virtual void SetTicks(Option_t *option="+"); // *MENU*
virtual void SetTimeDisplay(Int_t value) {fTimeDisplay = (value != 0);} // *TOGGLE*
virtual void SetTimeFormat(const char *format=""); // *MENU*
virtual void SetTimeOffset(Double_t toffset);
virtual void SetTimeOffset(Double_t toffset, Option_t *option="local");
virtual void UnZoom(); // *MENU*
ClassDef(TAxis,7) //Axis class
......
// @(#)root/hist:$Name: $:$Id: TAxis.cxx,v 1.50 2003/10/06 13:40:55 brun Exp $
// @(#)root/hist:$Name: $:$Id: TAxis.cxx,v 1.51 2003/10/08 07:55:26 brun Exp $
// Author: Rene Brun 12/12/94
/*************************************************************************
......@@ -936,22 +936,43 @@ void TAxis::SetTimeFormat(const char *tformat)
//______________________________________________________________________________
void TAxis::SetTimeOffset(Double_t toffset)
void TAxis::SetTimeOffset(Double_t toffset, Option_t *option)
{
// Change the time offset
char sqldate[20];
// If option = "gmt" the time offset is treated as a GMT time.
TString opt = option;
opt.ToLower();
Bool_t gmt = kFALSE;
if (opt.Contains("gmt")) gmt = kTRUE;
char tmp[20];
time_t timeoff;
struct tm* utctis;
Int_t IdF = fTimeFormat.Index("%F");
if (IdF>=0) fTimeFormat.Remove(IdF);
fTimeFormat.Append("%F");
timeoff = (time_t)((Long_t)(toffset));
utctis = localtime(&timeoff);
if (gmt) {
utctis = gmtime(&timeoff);
} else {
utctis = localtime(&timeoff);
}
strftime(tmp,256,"%Y-%m-%d %H:%M:%S",utctis);
fTimeFormat.Append(tmp);
// append the decimal part of the time offset
Double_t ds = toffset-(Int_t)toffset;
if(ds!= 0) {
sprintf(tmp,"s%g",ds);
fTimeFormat.Append(tmp);
}
strftime(sqldate,256,"%Y-%m-%d %H:%M:%S",utctis);
fTimeFormat.Append(sqldate);
// If the time is GMT, stamp fTimeFormat
if (gmt) fTimeFormat.Append(" GMT");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment