Index: /trunk/FACT++/src/Time.cc
===================================================================
--- /trunk/FACT++/src/Time.cc	(revision 15189)
+++ /trunk/FACT++/src/Time.cc	(revision 15190)
@@ -26,4 +26,9 @@
 // **************************************************************************
 #include "Time.h"
+
+#ifdef HAVE_LIBNOVA
+#include <libnova/solar.h>
+#include <libnova/rise_set.h>
+#endif
 
 using namespace std;
@@ -291,10 +296,110 @@
 //
 //! @returns
-//!     an int corresponding to the stored time minus 12 hours of the form
+//!     The time of the previous sun-rise, relative to given horizon in degree,
+//!     for the coordinates of the ORM, La Palma.
+//!     if libnova was not compiled in, it will return the next noon.
+//!
+//!  @throws
+//!     a runtime_error exception is thrown if the calculation of the sun-rise
+//!     by libnova fails (this would happen if libnova thinks the sun is
+//!     circumpolar which should never happen at La Palma)
+//
+Time Time::GetPrevSunRise(double horizon) const
+{
+#ifdef HAVE_LIBNOVA
+    const double lon = -(17.+53./60+26.525/3600);
+    const double lat =   28.+45./60+42.462/3600;
+
+    ln_lnlat_posn observer;
+    observer.lng = lon;
+    observer.lat = lat;
+
+    ln_rst_time sun_day;
+    if (ln_get_solar_rst_horizon(JD()-0.5, &observer, horizon, &sun_day)==1)
+        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
+
+    if (Time(sun_day.rise)<*this)
+        return Time(sun_day.rise);
+
+    if (ln_get_solar_rst_horizon(JD()-1.5, &observer, horizon, &sun_day)==1)
+        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
+
+    return Time(sun_day.rise);
+#else
+    return Time(floor(GetMjd()-0.5)+0.5);
+#endif
+}
+
+// --------------------------------------------------------------------------
+//
+//! @returns
+//!     The time of the next sun-rise, relative to given horizon in degree,
+//!     for the coordinates of the ORM, La Palma.
+//!     if libnova was not compiled in, it will return the next noon.
+//!
+//!  @throws
+//!     a runtime_error exception is thrown if the calculation of the sun-rise
+//!     by libnova fails (this would happen if libnova thinks the sun is
+//!     circumpolar which should never happen at La Palma)
+//
+Time Time::GetNextSunRise(double horizon) const
+{
+#ifdef HAVE_LIBNOVA
+    const double lon = -(17.+53./60+26.525/3600);
+    const double lat =   28.+45./60+42.462/3600;
+
+    ln_lnlat_posn observer;
+    observer.lng = lon;
+    observer.lat = lat;
+
+    ln_rst_time sun_day;
+    if (ln_get_solar_rst_horizon(JD()-0.5, &observer, horizon, &sun_day)==1)
+        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
+
+    if (Time(sun_day.rise)>=*this)
+        return Time(sun_day.rise);
+
+    if (ln_get_solar_rst_horizon(JD()+0.5, &observer, horizon, &sun_day)==1)
+        throw runtime_error("ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
+
+    return Time(sun_day.rise);
+#else
+    return Time(floor(GetMjd()+0.5))+0.5;
+#endif
+}
+
+// --------------------------------------------------------------------------
+//
+//! Calls GetPrevSunRise(LN_SOLAR_STANDART_HORIZON)
+//
+Time Time::GetPrevSunRise() const
+{
+    return GetPrevSunRise(LN_SOLAR_STANDART_HORIZON);
+}
+
+// --------------------------------------------------------------------------
+//
+//! Calls GetNextSunRise(LN_SOLAR_STANDART_HORIZON)
+//
+Time Time::GetNextSunRise() const
+{
+    return GetNextSunRise(LN_SOLAR_STANDART_HORIZON);
+}
+
+// --------------------------------------------------------------------------
+//
+//! @returns
+//!     Returns an int corresponding to the current sun-cycle, that means
+//!     the day of the last sun-rise w.r.t. this Time.
 //!     YYYYMMDD, e.g. 20111224 for Christmas eve 2011
+//!
+//! @remark
+//!     Before March 30th 2013, 12:00 noon was the reference and the
+//!     returned value belonged to the day of sun-set within the
+//!     24h period between two noon's.
 //
 int Time::NightAsInt() const
 {
-    const Time tm = *this - boost::posix_time::hours(12);
+    const Time tm = GetPrevSunRise();
     return tm.Y()*10000 + tm.M()*100 + tm.D();
 }
@@ -379,3 +484,2 @@
     return in;
 }
-
Index: /trunk/FACT++/src/Time.h
===================================================================
--- /trunk/FACT++/src/Time.h	(revision 15189)
+++ /trunk/FACT++/src/Time.h	(revision 15190)
@@ -113,4 +113,10 @@
     std::string SecondsTo(const Time & = Time()) const;
 
+    Time GetPrevSunRise(double horizon) const;
+    Time GetNextSunRise(double horizon) const;
+
+    Time GetPrevSunRise() const;
+    Time GetNextSunRise() const;
+
     int NightAsInt() const;
 };
