Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 3142)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 3148)
@@ -29,4 +29,21 @@
 // A generalized MARS time stamp.
 //
+//
+// We do not use floating point values here, because of several reasons:
+//  - having the times stored in integers only is more accurate and
+//    more reliable in comparison conditions
+//  - storing only integers gives similar bit-pattern for similar times
+//    which makes compression (eg gzip algorithm in TFile) more
+//    successfull
+//
+// Note, that there are many conversion function converting the day time
+// into a readable string. Also a direct interface to SQL time strings
+// is available.
+//
+// If you are using MTime containers as axis lables in root histograms
+// use GetAxisTime(). Make sure that you use the correct TimeFormat
+// on your TAxis (see GetAxisTime())
+//
+//
 // WARNING: Be carefull changing this class. It is also used in the
 //          MAGIC drive software cosy!
@@ -34,4 +51,5 @@
 // Remarke: If you encounter strange behaviour, check the casting.
 //          Note, that on Linux machines ULong_t and UInt_t is the same.
+//
 //
 // Version 1:
@@ -52,4 +70,6 @@
 
 #include <iomanip>
+
+#include <time.h>     // struct tm
 #include <sys/time.h> // struct timeval
 
@@ -65,4 +85,18 @@
 const UInt_t MTime::kHour = 3600000;         // [ms] one hour
 const UInt_t MTime::kDay  = MTime::kHour*24; // [ms] one day
+
+// --------------------------------------------------------------------------
+//
+// Constructor. Calls SetMjd(d) for d>0 in all other cases the time
+// is set to the current UTC time.
+//
+MTime::MTime(Double_t d)
+{
+    Init(0, 0);
+    if (d<=0)
+        Now();
+    else
+        SetMjd(d);
+}
 
 // --------------------------------------------------------------------------
@@ -192,4 +226,55 @@
 
     Set(mjd, tm, ms*1000);
+}
+
+// --------------------------------------------------------------------------
+//
+// Return contents as a TString of the form:
+//   "dd.mm.yyyy hh:mm:ss.fff"
+//
+Bool_t MTime::SetString(const char *str)
+{
+    if (!str)
+        return kFALSE;
+
+    UInt_t y, mon, d, h, m, s, ms;
+    const Int_t n = sscanf(str, "%02u.%02u.%04u %02u:%02u:%02u.%03u",
+                           &d, &mon, &y, &h, &m, &s, &ms);
+
+    return n==7 ? Set(y, mon, d, h, m, s, ms) : kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return contents as a TString of the form:
+//   "yyyy-mm-dd hh:mm:ss"
+//
+Bool_t MTime::SetSqlDateTime(const char *str)
+{
+    if (!str)
+        return kFALSE;
+
+    UInt_t y, mon, d, h, m, s;
+    const Int_t n = sscanf(str, "%04u-%02u-%02u %02u:%02u:%02u",
+                           &y, &mon, &d, &h, &m, &s);
+
+    return n==6 ? Set(y, mon, d, h, m, s) : kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return contents as a TString of the form:
+//   "yyyymmddhhmmss"
+//
+Bool_t MTime::SetSqlTimeStamp(const char *str)
+{
+    if (!str)
+        return kFALSE;
+
+    UInt_t y, mon, d, h, m, s;
+    const Int_t n = sscanf(str, "%04u%02u%02u%02u%02u%02u",
+                           &y, &mon, &d, &h, &m, &s);
+
+    return n==6 ? Set(y, mon, d, h, m, s) : kFALSE;
 }
 
@@ -255,5 +340,5 @@
 //
 // Return contents as a TString of the form:
-//   "yyyy/mm/dd hh:mm:ss.fff"
+//   "dd.mm.yyyy hh:mm:ss.fff"
 //
 TString MTime::GetString() const
@@ -265,5 +350,88 @@
     GetTime(h, m, s, ms);
 
-    return TString(Form("%4d/%02d/%02d %02d:%02d:%02d.%03d", y, mon, d, h, m, s, ms));
+    return TString(Form("%02d.%02d.%04d %02d:%02d:%02d.%03d", d, mon, y, h, m, s, ms));
+}
+
+// --------------------------------------------------------------------------
+//
+// Return contents as a string format'd with strftime:
+// Here is a short summary of the most important formats. For more
+// information see the man page (or any other description) of
+// strftime...
+//
+//  %a  The abbreviated weekday name according to the current locale.
+//  %A  The full weekday name according to the current locale.
+//  %b  The abbreviated month name according to the current locale.
+//  %B  The full month name according to the current locale.
+//  %c  The preferred date and time representation for the current locale.
+//  %d  The day of the month as a decimal number (range  01 to 31).
+//  %e  Like %d, the day of the month as a decimal number,
+//      but a leading zero is replaced by a space.
+//  %H  The hour as a decimal number using a 24-hour clock (range 00 to 23)
+//  %k  The hour (24-hour clock) as a decimal number (range 0 to 23);
+//      single digits are preceded by a blank.
+//  %m  The month as a decimal number (range 01 to 12).
+//  %M  The minute as a decimal number (range 00 to 59).
+//  %R  The time in 24-hour notation (%H:%M).  For a
+//      version including the seconds, see %T below.
+//  %S  The second as a decimal number (range 00 to 61).
+//  %T  The time in 24-hour notation (%H:%M:%S).
+//  %x  The preferred date representation for the current
+//      locale without the time.
+//  %X  The preferred time representation for the current
+//      locale without the date.
+//  %y  The year as a decimal number without a century (range 00 to 99).
+//  %Y  The year as a decimal number including the century.
+//  %+  The date and time in date(1) format.
+//
+// The default is: Tuesday 16.February 2004 12:17:22
+//
+// The maximum size of the return string is 128 (incl. NULL)
+//
+TString MTime::GetStringFmt(const char *fmt) const
+{
+    if (!fmt)
+        fmt = "%A %e.%B %Y %H:%M:%S";
+
+    UShort_t y, ms;
+    Byte_t mon, d, h, m, s;
+
+    GetDate(y, mon, d);
+    GetTime(h, m, s, ms);
+
+    struct tm time;
+    time.tm_sec   = s;
+    time.tm_min   = m;
+    time.tm_hour  = h;
+    time.tm_mday  = d;
+    time.tm_mon   = mon-1;
+    time.tm_year  = y-1900;
+    time.tm_isdst = 0;
+
+    // recalculate tm_yday and tm_wday
+    mktime(&time);
+
+    char ret[128];
+    return TString(strftime(ret, 127, fmt, &time) ? ret : "");
+}
+
+// --------------------------------------------------------------------------
+//
+// Return contents as a TString of the form:
+//   "yyyy-mm-dd hh:mm:ss"
+//
+TString MTime::GetSqlDateTime() const
+{
+    return GetStringFmt("%Y-%m-%d %H:%M:%S");
+}
+
+// --------------------------------------------------------------------------
+//
+// Return contents as a TString of the form:
+//   "yyyymmddhhmmss"
+//
+TString MTime::GetSqlTimeStamp() const
+{
+    return GetStringFmt("%Y%m%d%H%M%S");
 }
 
@@ -275,11 +443,5 @@
 TString MTime::GetFileName() const
 {
-    UShort_t y;
-    Byte_t mon, d, h, m, s;
-
-    GetDate(y, mon, d);
-    GetTime(h, m, s);
-
-    return TString(Form("%04d%02d%02d_%02d%02d%02d", y, mon, d, h, m, s));
+    return GetStringFmt("%Y%m%d_%H%M%S");
 }
 
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 3142)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 3148)
@@ -56,4 +56,5 @@
         Set(tm);
     }
+    MTime(Double_t d);
     MTime(const MTime& t) : fMjd(t.fMjd), fTime(t.fTime), fNanoSec(t.fNanoSec)
     {
@@ -77,4 +78,7 @@
     Bool_t   Set(UShort_t y, Byte_t m, Byte_t d, Byte_t h=13, Byte_t min=0, Byte_t s=0, UShort_t ms=0, UInt_t ns=0);
     void     Set(const struct timeval &tv);
+    Bool_t   SetString(const char *str);
+    Bool_t   SetSqlDateTime(const char *str);
+    Bool_t   SetSqlTimeStamp(const char *str);
     void     SetCT1Time(UInt_t mjd, UInt_t t1, UInt_t t0);
     Bool_t   UpdMagicTime(Byte_t h, Byte_t m, Byte_t s, UInt_t ns);
@@ -82,4 +86,7 @@
     Double_t GetMjd() const;
     TString  GetString() const;
+    TString  GetStringFmt(const char *fmt=0) const;
+    TString  GetSqlDateTime() const;
+    TString  GetSqlTimeStamp() const;
     TString  GetFileName() const;
     void     GetDate(UShort_t &y, Byte_t &m, Byte_t &d) const;
