13 #include "Preference.h"
18 #include "SpecialPixel.h"
19 #include "NaifStatus.h"
25 bool iTime::p_lpInitialized =
false;
42 iTime::iTime(
const QString &time) {
43 LoadLeapSecondKernel();
45 NaifStatus::CheckErrors();
49 str2et_c(time.toLatin1().data(), &et);
52 NaifStatus::CheckErrors();
66 void iTime::operator=(
const QString &time) {
67 LoadLeapSecondKernel();
69 NaifStatus::CheckErrors();
72 str2et_c(time.toLatin1().data(), &et);
75 NaifStatus::CheckErrors();
79 void iTime::operator=(
const char *time) {
80 LoadLeapSecondKernel();
82 NaifStatus::CheckErrors();
88 NaifStatus::CheckErrors();
93 void iTime::operator=(
const double time) {
94 LoadLeapSecondKernel();
105 bool iTime::operator>=(
const iTime &time) {
106 return (p_et >= time.
p_et);
116 bool iTime::operator<=(
const iTime &time) {
117 return (p_et <= time.
p_et);
127 bool iTime::operator>(
const iTime &time) {
128 return (p_et > time.
p_et);
139 bool iTime::operator<(
const iTime &time) {
140 return (p_et < time.
p_et);
150 bool iTime::operator!=(
const iTime &time) {
151 return (p_et != time.
p_et);
161 bool iTime::operator==(
const iTime &time) {
162 return (p_et == time.
p_et);
166 iTime iTime::operator +(
const double &secondsToAdd)
const {
173 void iTime::operator +=(
const double &secondsToAdd) {
174 if(!IsSpecial(secondsToAdd) && !IsSpecial(p_et))
175 p_et += secondsToAdd;
179 iTime operator +(
const double &secondsToAdd, iTime time) {
180 time += secondsToAdd;
187 iTime iTime::operator -(
const double &secondsToSubtract)
const {
189 tmp -= secondsToSubtract;
194 double iTime::operator -(
const iTime &iTimeToSubtract)
const {
195 return p_et - iTimeToSubtract.p_et;
199 void iTime::operator -=(
const double &secondsToSubtract) {
201 p_et -= secondsToSubtract;
205 iTime operator -(
const double &secondsToSubtract, iTime time) {
206 time -= secondsToSubtract;
220 QString iTime::YearString()
const {
229 int iTime::Year()
const {
230 NaifStatus::CheckErrors();
234 timout_c(p_et,
"YYYY", 5, out);
235 NaifStatus::CheckErrors();
244 QString iTime::MonthString()
const {
253 int iTime::Month()
const {
254 NaifStatus::CheckErrors();
258 timout_c(p_et,
"MM", 3, out);
259 NaifStatus::CheckErrors();
268 QString iTime::DayString()
const {
277 int iTime::Day()
const {
278 NaifStatus::CheckErrors();
282 timout_c(p_et,
"DD", 3, out);
283 NaifStatus::CheckErrors();
292 QString iTime::HourString()
const {
301 int iTime::Hour()
const {
302 NaifStatus::CheckErrors();
306 timout_c(p_et,
"HR", 3, out);
307 NaifStatus::CheckErrors();
316 QString iTime::MinuteString()
const {
325 int iTime::Minute()
const {
326 NaifStatus::CheckErrors();
330 timout_c(p_et,
"MN", 3, out);
331 NaifStatus::CheckErrors();
340 QString iTime::SecondString(
int precision)
const {
342 osec.setf(ios::fixed);
343 osec << setprecision(precision) << Second();
344 QString sSeconds(osec.str().c_str());
345 sSeconds = sSeconds.remove(QRegExp(
"(\\.0*|0*)$"));
347 if(sSeconds.isEmpty()) sSeconds =
"0";
356 double iTime::Second()
const {
357 NaifStatus::CheckErrors();
361 timout_c(p_et,
"SC.#######::RND", 256, out);
362 NaifStatus::CheckErrors();
371 QString iTime::DayOfYearString()
const {
380 int iTime::DayOfYear()
const {
381 NaifStatus::CheckErrors();
385 timout_c(p_et,
"DOY", 4, out);
386 NaifStatus::CheckErrors();
396 QString iTime::EtString()
const {
405 QString iTime::UTC(
int precision)
const {
406 QString utc = YearString() +
"-" ;
407 if(Month() < 10) utc +=
"0" + MonthString() +
"-";
408 else utc += MonthString() +
"-";
410 if(Day() < 10) utc +=
"0" + DayString() +
"T";
411 else utc += DayString() +
"T";
413 if(Hour() < 10) utc +=
"0" + HourString() +
":";
414 else utc += HourString() +
":";
416 if(Minute() < 10) utc +=
"0" + MinuteString() +
":";
417 else utc += MinuteString() +
":";
419 if(Second() < 10) utc +=
"0" + SecondString(precision);
420 else utc += SecondString(precision);
425 void iTime::setEt(
double et) {
432 void iTime::setUtc(QString utcString) {
434 if ( utcString.contains(
"T") &&
435 !utcString.contains(
"-") &&
436 !utcString.contains(
":")) {
437 QString dateString = utcString.split(
"T").front();
438 dateString.insert(4,
"-");
441 if (dateString.size() > 8) {
442 dateString.insert(7,
"-");
445 QString timeString = utcString.split(
"T").back();
447 if (timeString.size() < 6) {
448 timeString.resize(6,
'0');
450 timeString.insert(2,
":");
451 timeString.insert(5,
":");
453 utcString = dateString +
"T" + timeString;
456 NaifStatus::CheckErrors();
457 LoadLeapSecondKernel();
460 utc2et_c(utcString.toLatin1().data(), &et);
462 NaifStatus::CheckErrors();
471 void iTime::LoadLeapSecondKernel() {
474 if(p_lpInitialized)
return;
478 QString baseDir = dataDir[
"Base"];
479 baseDir +=
"/kernels/lsk/";
480 FileName leapSecond(baseDir +
"naif????.tls");
482 NaifStatus::CheckErrors();
484 furnsh_c(leapSecondName.toLatin1().data());
485 NaifStatus::CheckErrors();
487 p_lpInitialized =
true;
497 QString iTime::CurrentGMT() {
498 time_t startTime = time(NULL);
499 struct tm *tmbuf = gmtime(&startTime);
501 strftime(timestr, 80,
"%Y-%m-%dT%H:%M:%S", tmbuf);
502 return (QString) timestr;
513 QString iTime::CurrentLocalTime() {
514 time_t startTime = time(NULL);
515 struct tm *tmbuf = localtime(&startTime);
517 strftime(timestr, 80,
"%Y-%m-%dT%H:%M:%S", tmbuf);
518 return (QString) timestr;