Ignore:
Timestamp:
06/12/07 21:43:17 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MTime.cc

    r8379 r8551  
    8989using namespace std;
    9090
    91 const UInt_t MTime::kHour = 3600000;         // [ms] one hour
    92 const UInt_t MTime::kDay  = MTime::kHour*24; // [ms] one day
     91const UInt_t MTime::kHour   = 3600000;         // [ms] one hour
     92const UInt_t MTime::kDay    = MTime::kHour*24; // [ms] one day
     93const UInt_t MTime::kDaySec = 3600*24;         // [s] one day
    9394
    9495// --------------------------------------------------------------------------
     
    238239TDatime MTime::GetRootDatime() const
    239240{
    240     return TDatime((UInt_t)((GetMjd()-40587)*kDay/1000));
     241    return TDatime((UInt_t)((GetMjd()-40587)*kDaySec));
    241242}
    242243
     
    252253Double_t MTime::GetAxisTime() const
    253254{
    254     return (GetMjd()-49718)*kDay/1000;
     255    return (GetMjd()-49718)*kDaySec;
    255256}
    256257
     
    261262void MTime::SetAxisTime(Double_t time)
    262263{
    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//
     271void 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//
     286void MTime::Set(const struct timeval &tv)
     287{
     288    SetUnixTime(tv.tv_sec, tv.tv_usec);
    273289}
    274290
     
    342358
    343359    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);
    358360}
    359361
     
    489491    const Double_t r2 = 86400.0*ut;
    490492
    491     const Double_t sum = (r1+r2)/(24*3600);
     493    const Double_t sum = (r1+r2)/kDaySec;
    492494
    493495    return fmod(sum, 1)*TMath::TwoPi();//+TMath::TwoPi();
     
    975977void MTime::SetMean(Double_t t0, Double_t t1)
    976978{
    977     const Double_t mean = (t0+t1)*(500./kDay);
     979    const Double_t mean = (t0+t1)*(0.5/kDaySec);
    978980    SetMjd(mean);
    979981}
  • trunk/MagicSoft/Mars/mbase/MTime.h

    r8379 r8551  
    2727{
    2828public:
    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
    3132
    3233    enum {
     
    9899    void     SetMjd(Double_t m);
    99100    void     SetAxisTime(Double_t time);
    100     void     SetUnixTime(Long_t time);
     101    void     SetUnixTime(Long64_t sec, ULong64_t usec=0);
    101102    void     SetEaster(Short_t year=0);
    102103
     
    126127    }
    127128
    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;
    135141    UInt_t DayOfYear() const;
    136     Int_t  Week() const    { Short_t y; return Week(y); }
    137     Int_t  Week(Short_t &year) const;
    138142
    139143    Bool_t IsMidnight() const { return (Long_t)fTime==0 && fNanoSec==0; }
Note: See TracChangeset for help on using the changeset viewer.