TDatime / dates before 1995

Hi there,
I’m trying to create a plot with the number of lines of code of
the Linux kernel from 1991 until today. The obvious idea is
to use different TGraph objects for the various kernel versions,
and to make the x-axis display the date. This cannot be done
with TDatime, though, as dates before 1995 seem to be illegal.
Any idea ?
Thanks in advance,
Ruediger Berlich

Hi,

We have an “HowTo” explaining the time on axis usage:
root.cern.ch/root/HowtoTimeAxis.html

Also there is several example in $ROOTSYS/tutorials/ . Just look at the macros named time.C

Finnaly, here is an example not using TDatime:

timeonaxis4 ()
{
   TGraph *graph = new TGraph;
   gStyle->SetTimeOffset(0);
   graph->SetPoint(0, 509363595.000000,1.0);
   graph->SetPoint(1,1109376948.000000,2.0);
   graph->Draw("AC*");
   TH1F *hist = graph->GetHistogram();
   TAxis *axis = hist->GetXaxis();
   axis->SetTimeDisplay(1);
   axis->SetTimeFormat("%Y-%m-%d");
   axis->SetNdivisions(202,false);
}

Hi Olivier,
Thanks. I had already followed the examples in the tutorials
directory. However, with code like

[…]
TDatime releaseTime;
int t[35], x[35];
releaseTime.Set(1994,05,23,0,0,0);
t[0]=releaseTime.Convert(); x[0]=182113;
[…]

I get the error message
Error in : year must be >= 1995
This is with v. 5.11.02 of ROOT.

Hence I wrote the first mail. I will try to use the
code at the end of your mail.

Thanks for your help,
Ruediger

[quote=“couet”]Hi,

We have an “HowTo” explaining the time on axis usage:
root.cern.ch/root/HowtoTimeAxis.html

Also there is several example in $ROOTSYS/tutorials/ . Just look at the macros named time.C

Finnaly, here is an example not using TDatime:

timeonaxis4 () { TGraph *graph = new TGraph; gStyle->SetTimeOffset(0); graph->SetPoint(0, 509363595.000000,1.0); graph->SetPoint(1,1109376948.000000,2.0); graph->Draw("AC*"); TH1F *hist = graph->GetHistogram(); TAxis *axis = hist->GetXaxis(); axis->SetTimeDisplay(1); axis->SetTimeFormat("%Y-%m-%d"); axis->SetNdivisions(202,false); } [/quote]

Hi there,

o.k., I suppose the question is now how to get a mapping
from mm-dd-yyyy to the numbers you use in your code
(in the SetPoint() call) . The first number (509363595)
seems to correspond to 01-01-85 , according to the
graphical display.

However, if I run
date -d “01/01/1985” +%s
in the shell I get 473382000

Running

{
struct tm sometime;

sometime.tm_hour=0;
sometime.tm_min=0;
sometime.tm_sec=0;

sometime.tm_year=1985-1900;
sometime.tm_mon=1-0;
sometime.tm_mday=1;

cout << mktime(&sometime) << endl;
}

in ROOT 5.11/02 gives me 476060400 ,
i.e. yet another number (possibly because of
daylight-saving issues and/or leap second
issues ?).

So I’m at a loss, as I do not know how to convert
my dates to the number expected by SetPoint.

Thanks and Best Regards,
Ruediger

Small correction:

sometime.tm_mon=1-0;
should read
sometime.tm_mon=0;

I then get the same output as for
date -d “01/01/1985” +%s

The number still is different from the
one used in SetPoint …

Have a good day,
Ruediger

seems do me the following macro is correct:

timeonaxis4 ()
{
   TGraph *graph = new TGraph;
   gStyle->SetTimeOffset(0);
                                                                                
   // Point 1 given by : date -d "01/01/1985" +%s
   graph->SetPoint(0, 473382000.0     ,1.0);
                                                                                
   // Point 2 given by : date -d "07/02/1985" +%s
   graph->SetPoint(1, 489103200.0     ,2.0);
                                                                                
   // Point 3 given by : date -d "01/01/1986" +%s
   graph->SetPoint(2, 504918000.0     ,3.0);
                                                                                
   graph->Draw("AL*");
   TH1F *hist = graph->GetHistogram();
   TAxis *axis = hist->GetXaxis();
   axis->SetTimeDisplay(1);
   axis->SetTimeFormat("%Y-%m-%d");
   axis->SetNdivisions(204,false);
}