Changeset 8551 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 06/12/07 21:43:17 (18 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MTime.cc
r8379 r8551 89 89 using namespace std; 90 90 91 const UInt_t MTime::kHour = 3600000; // [ms] one hour 92 const UInt_t MTime::kDay = MTime::kHour*24; // [ms] one day 91 const UInt_t MTime::kHour = 3600000; // [ms] one hour 92 const UInt_t MTime::kDay = MTime::kHour*24; // [ms] one day 93 const UInt_t MTime::kDaySec = 3600*24; // [s] one day 93 94 94 95 // -------------------------------------------------------------------------- … … 238 239 TDatime MTime::GetRootDatime() const 239 240 { 240 return TDatime((UInt_t)((GetMjd()-40587)*kDay /1000));241 return TDatime((UInt_t)((GetMjd()-40587)*kDaySec)); 241 242 } 242 243 … … 252 253 Double_t MTime::GetAxisTime() const 253 254 { 254 return (GetMjd()-49718)*kDay /1000;255 return (GetMjd()-49718)*kDaySec; 255 256 } 256 257 … … 261 262 void MTime::SetAxisTime(Double_t time) 262 263 { 263 SetMjd(time*1000/kDay+49718); 264 } 265 266 // -------------------------------------------------------------------------- 267 // 268 // Set unix time (seconds since epoche 1970-01-01) 269 // 270 void MTime::SetUnixTime(Long_t tm) 271 { 272 SetMjd(1000.*tm/kDay+40587); 264 SetMjd(time/kDaySec+49718); 265 } 266 267 // -------------------------------------------------------------------------- 268 // 269 // Set unix time (seconds since epoche 1970-01-01 00:00) 270 // 271 void MTime::SetUnixTime(Long64_t sec, ULong64_t usec) 272 { 273 const Long64_t totsec = sec + usec/1000000; 274 const UInt_t mjd = totsec/kDaySec + 40587; 275 276 const UInt_t ms = totsec%kDaySec*1000 + (usec/1000)%1000; 277 const UInt_t us = usec%1000; 278 279 SetMjd(mjd, ms, us*1000); 280 } 281 282 // -------------------------------------------------------------------------- 283 // 284 // Set MTime to time expressed in a 'struct timeval' 285 // 286 void MTime::Set(const struct timeval &tv) 287 { 288 SetUnixTime(tv.tv_sec, tv.tv_usec); 273 289 } 274 290 … … 342 358 343 359 return SetMjd(mjd, tm, ns); 344 }345 346 // --------------------------------------------------------------------------347 //348 // Set MTime to time expressed in a 'struct timeval'349 //350 void MTime::Set(const struct timeval &tv)351 {352 const UInt_t mjd = (UInt_t)TMath::Floor(1000.*tv.tv_sec/kDay) + 40587;353 354 const Long_t tm = tv.tv_sec%(24*3600)*1000 + tv.tv_usec/1000;355 const UInt_t ms = tv.tv_usec%1000;356 357 SetMjd(mjd, tm, ms*1000);358 360 } 359 361 … … 489 491 const Double_t r2 = 86400.0*ut; 490 492 491 const Double_t sum = (r1+r2)/ (24*3600);493 const Double_t sum = (r1+r2)/kDaySec; 492 494 493 495 return fmod(sum, 1)*TMath::TwoPi();//+TMath::TwoPi(); … … 975 977 void MTime::SetMean(Double_t t0, Double_t t1) 976 978 { 977 const Double_t mean = (t0+t1)*( 500./kDay);979 const Double_t mean = (t0+t1)*(0.5/kDaySec); 978 980 SetMjd(mean); 979 981 } -
trunk/MagicSoft/Mars/mbase/MTime.h
r8379 r8551 27 27 { 28 28 public: 29 static const UInt_t kHour; // [ms] one hour 30 static const UInt_t kDay; // [ms] one day 29 static const UInt_t kHour; // [ms] one hour 30 static const UInt_t kDay; // [ms] one day 31 static const UInt_t kDaySec; // [s] one day 31 32 32 33 enum { … … 98 99 void SetMjd(Double_t m); 99 100 void SetAxisTime(Double_t time); 100 void SetUnixTime(Long _t time);101 void SetUnixTime(Long64_t sec, ULong64_t usec=0); 101 102 void SetEaster(Short_t year=0); 102 103 … … 126 127 } 127 128 128 UInt_t Year() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; } 129 UInt_t Month() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; } 130 UInt_t Day() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; } 131 Byte_t WeekDay() const { return TMath::Nint(TMath::Floor(GetMjd()+3))%7; } // Return Day of the week: Sun=0, Mon=1, ..., Sat=6 132 UInt_t Hour() const { Byte_t h, m, s; GetTime(h,m,s); return h; } 133 UInt_t Min() const { Byte_t h, m, s; GetTime(h,m,s); return m; } 134 UInt_t Sec() const { Byte_t h, m, s; GetTime(h,m,s); return s; } 129 UInt_t Year() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; } 130 UInt_t Month() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; } 131 UInt_t Day() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; } 132 Byte_t WeekDay() const { return TMath::Nint(TMath::Floor(GetMjd()+3))%7; } // Return Day of the week: Sun=0, Mon=1, ..., Sat=6 133 UInt_t Hour() const { Byte_t h, m, s; GetTime(h,m,s); return h; } 134 UInt_t Min() const { Byte_t h, m, s; GetTime(h,m,s); return m; } 135 UInt_t Sec() const { Byte_t h, m, s; GetTime(h,m,s); return s; } 136 UInt_t MilliSec() const { return (GetTime()+kDay)%1000; } 137 UInt_t MicroSec() const { return fNanoSec/1000+MilliSec()*1000; } 138 UInt_t NanoSec() const { return fNanoSec+MilliSec()*1000000; } 139 Int_t Week() const { Short_t y; return Week(y); } 140 Int_t Week(Short_t &year) const; 135 141 UInt_t DayOfYear() const; 136 Int_t Week() const { Short_t y; return Week(y); }137 Int_t Week(Short_t &year) const;138 142 139 143 Bool_t IsMidnight() const { return (Long_t)fTime==0 && fNanoSec==0; }
Note:
See TracChangeset
for help on using the changeset viewer.