Index: /trunk/FACT++/src/dataLogger.cc
===================================================================
--- /trunk/FACT++/src/dataLogger.cc	(revision 10973)
+++ /trunk/FACT++/src/dataLogger.cc	(revision 10974)
@@ -239,6 +239,6 @@
     string fFullNightlyReportFileName;
     ///variable to track when the statistic were last calculated
-    double fPreviousStatsUpdateTime;
-    double fPreviousOldRunNumberCheck;
+    Time fPreviousStatsUpdateTime;
+    Time fPreviousOldRunNumberCheck;
     ///boolean to know whether we should close and reopen daily files or not
     bool fDailyFileDayChangedAlready;
@@ -396,4 +396,8 @@
     ///Checks if a given path exist
     bool DoesPathExist(string path);
+    ///Check if the statistics service should be updated, and if so, do it
+    void UpdateStatisticsService();
+    ///Check if old run numbers can be trimmed, and if so, do it
+    void TrimOldRunNumbers();
 public:
     ///Create a given directory
@@ -1104,5 +1108,49 @@
     }
 }
-
+// --------------------------------------------------------------------------
+//
+//! checks if the statistic service should be updated, and if so, do it
+//
+void DataLogger::UpdateStatisticsService()
+{
+    //update the fits files sizes
+    const Time cTime = Time();
+
+    if ((fStatsPeriodDuration == 0) || ((cTime - fPreviousStatsUpdateTime).total_seconds() < fStatsPeriodDuration))
+        return;
+
+    calculateTotalSizeWritten(fStatVar, false);
+    fStatVar.writingRate = (fStatVar.sizeWritten - fPreviousSize)/((cTime - fPreviousStatsUpdateTime).total_seconds());
+    fPreviousSize = fStatVar.sizeWritten;
+    fPreviousStatsUpdateTime = cTime;
+    //update the service. No need to check if data has been written, because some must have been, otherwise we would not have hit this piece of code
+    fStatsMonitoring->updateService();
+
+    if(fDebugIsOn)
+    {
+        ostringstream str;
+        str << "Size written: " << fStatVar.sizeWritten/1000 << " kB; writing rate: ";
+        str << fStatVar.writingRate/1000 << " kB/s; free space: ";
+        str << fStatVar.freeSpace/(1000*1000) << " MB";
+        Debug(str);
+    }
+}
+// --------------------------------------------------------------------------
+//
+//! checks if old run numbers should be trimmed and if so, do it
+//
+void DataLogger::TrimOldRunNumbers()
+{
+    const Time cTime = Time();
+
+    if ((cTime - fPreviousOldRunNumberCheck).total_seconds() < fRunNumberTimeout*60)
+        return;
+
+    while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::minutes(fRunNumberTimeout))
+    {
+         RemoveOldestRunNumber();
+    }
+    fPreviousOldRunNumberCheck = cTime;
+}
 // --------------------------------------------------------------------------
 //
@@ -1154,31 +1202,8 @@
 
     //update the fits files sizes
-    const Time cTime = Time();
-    if ((fStatsPeriodDuration != 0) && ((cTime.Mjd() - fPreviousStatsUpdateTime)*24*60*60 > fStatsPeriodDuration))
-    {
-        calculateTotalSizeWritten(fStatVar, false);
-        fStatVar.writingRate = (fStatVar.sizeWritten - fPreviousSize)/((cTime.Mjd() - fPreviousStatsUpdateTime)*24*60*60);
-        fPreviousSize = fStatVar.sizeWritten;
-        fPreviousStatsUpdateTime = cTime.Mjd();
-        //update the service. No need to check if data has been written, because some must have been, otherwise we would not have hit this piece of code
-        fStatsMonitoring->updateService();
-
-        if(fDebugIsOn)
-        {
-            ostringstream str;
-            str << "Size written: " << fStatVar.sizeWritten/1000 << " kB; writing rate: ";
-            str << fStatVar.writingRate/1000 << " kB/s; free space: ";
-            str << fStatVar.freeSpace/(1000*1000) << " MB";
-            Debug(str);
-        }
-    }
-    if ((cTime.Mjd() - fPreviousOldRunNumberCheck)*24*60 >= fRunNumberTimeout)
-    {
-        while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::minutes(fRunNumberTimeout))
-        {
-             RemoveOldestRunNumber();
-        }
-        fPreviousOldRunNumberCheck = cTime.Mjd();
-    }
+    UpdateStatisticsService();
+
+    //remove old run numbers
+    TrimOldRunNumbers();
 }
 // --------------------------------------------------------------------------
