15 #include "TUnixTime.h"
24 if (!fUTime) fUTime = time(0);
27 TUnixTime::TUnixTime(Int_t date,Int_t time,
int gmt)
29 if (gmt) SetGTime(date,time);
30 else SetLTime(date,time);
33 TUnixTime::TUnixTime(
const TDatime &tdt,
int gmt)
35 if (gmt) {SetGTime(tdt.GetDate(),tdt.GetTime());}
36 else {SetLTime(tdt.GetDate(),tdt.GetTime());}
39 void TUnixTime::SetGTime(
const struct tm *tm_gmt)
46 ugmt = mktime(&tm_test)-timezone;
47 for (
int iter=0;iter<24;iter++) {
48 tm_test = *gmtime(&ugmt);
50 dif = tm_test.tm_year - tm_gmt->tm_year;
52 dif = tm_test.tm_mon - tm_gmt->tm_mon ;
54 dif = tm_test.tm_mday - tm_gmt->tm_mday;
56 dif = tm_test.tm_hour - tm_gmt->tm_hour;
58 UPD:
if (dif<0) ugmt+=3600;
66 void TUnixTime::SetLTime(
const struct tm *lt)
70 fUTime = mktime(<t);
73 static void DateTime2tm(
struct tm *gt,Int_t idate, Int_t itime)
76 *gt = *localtime(&ul);
78 if (idate < 19000000) idate +=19000000;
79 if (idate < 19500000) idate += 1000000;
80 gt->tm_year= ((idate/10000)-1900);
81 gt->tm_mon = ((idate/100)%100) - 1;
82 gt->tm_mday= ((idate )%100);
83 gt->tm_hour= itime/10000;
84 gt->tm_min = (itime/100 )%100;
85 gt->tm_sec = (itime )%100;
89 static void tm2DateTime(Int_t &idate, Int_t &itime,
const struct tm *gt)
91 idate = (gt->tm_year+1900)*10000 + (gt->tm_mon+1)*100 + gt->tm_mday;
92 itime = gt->tm_hour*10000 + gt->tm_min*100 + gt->tm_sec;
96 void TUnixTime::SetGTime(Int_t idate, Int_t itime)
99 DateTime2tm(>,idate,itime);
104 void TUnixTime::SetLTime(Int_t idate, Int_t itime)
107 DateTime2tm(>,idate,itime);
112 void TUnixTime::GetGTime(Int_t &idate, Int_t &itime)
114 std::time_t utime = fUTime;
115 std::tm *gt = gmtime(&utime);
116 tm2DateTime(idate, itime, gt);
120 void TUnixTime::GetLTime(Int_t &idate, Int_t &itime)
122 std::time_t utime = fUTime;
123 std::tm *gt = localtime(&utime);
124 tm2DateTime(idate, itime, gt);
127 TString TUnixTime::GetLString()
129 std::time_t utime = fUTime;
130 return TString(ctime(&utime));
133 TString TUnixTime::GetGString()
135 std::time_t utime = fUTime;
136 return TString(asctime(gmtime(&utime)));
139 void TUnixTime::SetLTime(
const TDatime &loc)
141 SetLTime(loc.GetDate(), loc.GetTime());
144 void TUnixTime::SetGTime(
const TDatime &gmt)
146 SetGTime(gmt.GetDate(), gmt.GetTime());
149 ULong_t TUnixTime::Convert(
const TDatime &dt,
int gmt)
152 if (gmt) {ux.SetGTime(dt);}
153 else {ux.SetLTime(dt);}
154 return ux.GetUTime();