Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 19770)
+++ /trunk/FACT++/src/datalogger.cc	(revision 19771)
@@ -349,5 +349,5 @@
     string CompileFileNameWithPath(const string &path, const string &service, const string & extension);
     ///Form the file names only
-    string CompileFileName(const string& service, const string& extension, const Time& time=Time()) const;
+    string CompileFileName(const string& service, const string& extension, const uint32_t& night) const;
     ///Check whether service is in black and/or white list
     bool ShouldSubscribe(const string& server, const string& service);
@@ -831,10 +831,9 @@
 //! @param extension the extension to add, if any
 //
-string DataLogger::CompileFileName(const string& service, const string& extension, const Time& time) const
+string DataLogger::CompileFileName(const string& service, const string& extension, const uint32_t& night) const
 {
     ostringstream str;
 
-    const Time ftime(time);//removed this as already done by nightAsInt: -boost::posix_time::hours(12));
-    str << ftime.NightAsInt();
+    str << night;
 
     if (!service.empty())
@@ -853,10 +852,16 @@
     const Time time;
 
-    //calculate time suitable for naming files.
-    //fCurrentDay is 30 minutes after upcoming sunrise. So just use 12 hours before then
+    // calculate time suitable for naming files. Get a time between the next sun-rise (fCurrentDay)
+    // and the previous sun-rise so that NightAsInt (which refers to the previous sun-rise)
+    // provides reasonable results.
+
+    // WARNING: This fails if the sun-rise is around midnight UTC!
+    // It would be more appropriate to relate the "NightAsInt" to
+    // the LOCAL time of sun-rise!
     const Time ftime = fCurrentDay-boost::posix_time::hours(12);
 
     //output it
-    str << path << ftime.GetAsStr("/%Y/%m/%d");
+    const uint32_t night = ftime.NightAsInt();
+    str << path << Tools::Form("/%04d/%02d/%02d/", night/10000, (night/100)%100, night%100);
 
     //check if target directory exist
@@ -864,5 +869,5 @@
         CreateDirectory(str.str());
 
-    str << '/' << CompileFileName(service, extension, ftime);//fCurrentDay);
+    str << '/' << CompileFileName(service, extension, night);//fCurrentDay);
 
     return str.str();
