Operations on TDatime

Hello,
is it possible to do operation on TDatime object. It seems the answer is no so I would like to know if there is a way to do it.
For example, I have a date/time such as 2015/01/28 10h00m00s. I would like that a ROOT object allow to substract 12h to this date and therefore to get 2015/01/27 22h00m00s
Of course, I would like also to add time.
Do you have any idea on how to do that?

Hi,

Look at the TDatime documentation. Based on your example:

TDatime d(2015, 01, 28, 14, 23, 0);
d.AsString();
(const char* 0x32d7b909e0)"Wed Jan 28 14:23:00 2015"
d.Set(d.GetYear(), d.GetMonth(), d.GetDay(), d.GetHour()-12, d.GetMinute(), d.GetSecond());
d.AsString();
(const char* 0x32d7b909e0)"Wed Jan 28 02:23:00 2015"

Cheers, Bertrand.

Hmm, this is what I get

[quote]root [2] TDatime t(2015,1,28,3,30,00)
root [3] t.AsString()
(const char* 0x36921909e0)"Wed Jan 28 03:30:00 2015"
root [4] t.Set(t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour()-12,t.GetMinute(),t.GetSecond())
root [5] t.AsString()
(const char* 0x36921909e0)“Mon Mar 31 23:30:00 2059”[/quote]
Thus, there is clearly a problem when the day should change (maybe also other field (year, month, minute, …)). I expected to have something like

Anyway, I found TTimeStamp that works well.

Can you reproduce the bug I described above? I use the latest ROOT version : 5.34/25.

Hi,

Yes, I can reproduce it… I’ll investigate.

Cheers, Bertrand.

Well, the TDatime::Set method is actually only setting (literally) the numbers passed as argument, and there is no check if those numbers are positive or not. But as you say [quote=“pamputt”]Anyway, I found TTimeStamp that works well.[/quote]Then I don’t think I will investigate and implement complete date/time caculation (e.g. t.GetHour()-12 in your example would change the time AND the day) in the TDatime::Set method…

Cheers, Bertrand.