30 #include "../externals/nova.h" 63 *
this = microsec_clock::universal_time();
66 *
this = microsec_clock::local_time();
88 Time::Time(
const boost::date_time::special_values &val) : ptime(val)
104 : ptime(
fUnixOffset, time_duration(0, 0, tm, usec*pow(10, time_duration::num_fractional_digits()-6)))
116 : ptime(
fUnixOffset, time_duration(0, 0, tv.tv_sec, tv.tv_usec*pow(10, time_duration::num_fractional_digits()-6)))
128 Time::Time(
short year,
unsigned char month,
unsigned char day,
129 unsigned char hh,
unsigned char mm,
unsigned char ss,
unsigned int microsec)
131 : ptime(
boost::gregorian::date(year, month, day),
132 time_duration(hh, mm, ss, microsec*pow(10, time_duration::num_fractional_digits()-6)))
152 mjd *= 24*60*60*time_duration::ticks_per_second();
154 *
this = ptime(
fUnixOffset, time_duration(0, 0, 0, mjd));
163 const time_duration tod = time_of_day();
165 const double frac = double(tod.fractional_seconds())/time_duration::ticks_per_second();
166 const double sec = tod.total_seconds()+frac;
182 return date().modjulian_day()+
SecondsOfDay()/(24*60*60);
197 return (date().modjulian_day()-40587)*24*60*60 +
SecondsOfDay();
206 return (date().modjulian_day()-40587) +
SecondsOfDay()/(24*60*60);
215 return (date().modjulian_day()-40587)*24*60*60 + time_of_day().total_seconds();
224 return (date().modjulian_day()-49718)*24*60*60 +
SecondsOfDay();
256 out << Time::iso << *
this;
288 return str.str().substr(0, 5);
298 return str.str().substr(str.str().substr(0, 3)==
"00:" ? 3 : 0, 5);
319 if (ln_get_solar_rst_horizon(
JD()-0.5, &obs, horizon, &sun_day)==1)
320 throw runtime_error(
"ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
322 if (
Time(sun_day.rise)<*
this)
323 return Time(sun_day.rise);
325 if (ln_get_solar_rst_horizon(
JD()-1.5, &obs, horizon, &sun_day)==1)
326 throw runtime_error(
"ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
328 return Time(sun_day.rise);
330 return Time(floor(
Mjd()-0.5)+0.5);
352 if (ln_get_solar_rst_horizon(
JD()-0.5, &obs, horizon, &sun_day)==1)
353 throw runtime_error(
"ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
355 if (
Time(sun_day.rise)>=*
this)
356 return Time(sun_day.rise);
358 if (ln_get_solar_rst_horizon(
JD()+0.5, &obs, horizon, &sun_day)==1)
359 throw runtime_error(
"ln_get_solar_rst_horizon reported the sun to be circumpolar at the coordinates of La Palma!");
361 return Time(sun_day.rise);
363 return Time(floor(
Mjd()+0.5))+0.5;
400 return tm.
Y()*10000 + tm.
M()*100 + tm.
D();
442 const locale loc(locale::classic(),
443 f.
ptr==0 ? 0 :
new time_facet(f.
ptr));
475 const locale loc(locale::classic(),
476 f.
ptr==0 ? 0 :
new time_input_facet(f.
ptr));
static const _time_format sql
set to format to the iso standard
Time(enum init_t type=utc)
Adds some functionality to boost::posix_time::ptime for our needs.
uint32_t NightAsInt() const
static const _time_format iso
set to format to the sql format (without the fraction of seconds)
static const _time_format reset
std::string SecondsTo(const Time &=Time()) const
double SecondsOfDay() const
static const _time_format ssql
set to format to the sql format
static const _time_format magic
set to format to the extended iso standard
Time GetPrevSunRise() const
Calls GetPrevSunRise(LN_SOLAR_STANDART_HORIZON)
static const boost::gregorian::date fUnixOffset
Points to the famous 1/1/1970, the standard offset for unix times.
static const _time_format def
Remove the format description from the stream.
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
ostream & operator<<(ostream &out, const _time_format &f)
static const Time None
A none-time, this can be used as a simple representation of an invalid time.
static const _time_format fmt(const char *txt=0)
A stream manipulator to set the output/input format.
void SetFromStr(const std::string &str, const char *fmt="%Y-%m-%d %H:%M:%S")
static const _time_format std
set to format to the locale default
Time GetNextSunRise() const
Calls GetNextSunRise(LN_SOLAR_STANDART_HORIZON)
istream & operator>>(istream &in, const _time_format &f)
std::string MinutesTo(const Time &=Time()) const
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
static const _time_format smagic
set to format to the MAGIC report format
Do not initialize the time.
init_t
set to format to the MAGIC report format (without the fraction of seconds)