ExtDateTime parsePlanckDate(const QString& dateString) {
  QStringList secondSplit = QStringList::split('.', dateString);
  if (secondSplit.isEmpty() || secondSplit.count() > 2) {
    return ExtDateTime();
  }

  int seconds = 0;
  if (secondSplit.count() > 1) {
    seconds = secondSplit[1].toUInt();
  }

  QStringList mainSplit = QStringList::split(':', secondSplit[0]);
  ExtDateTime edt = ExtDateTime::currentDateTime();
  int offset = ExtDateTime::currentDateTime(Qt::UTC).toTime_t() - edt.toTime_t();
  ExtDate d = edt.date();
  QTime t = edt.time();
  int i = 0;
  switch (mainSplit.count()) {
    default:
      return ExtDateTime();
    case 5:
      {
        int years = mainSplit[i++].toInt();
        if (years < 100) {
          if (years < 0) {
            years = 1970 - years;
          } else {
            years += 2000;
          }
        }
        d.setYMD(years, d.month(), d.day());
      }
    case 4:
      {
        unsigned month = mainSplit[i++].toUInt();
        d.setYMD(d.year(), month, d.day());
      }
    case 3:
      {
        unsigned day = mainSplit[i++].toInt();
        d.setYMD(d.year(), d.month(), day);
      }
      edt.setDate(d);
    case 2:
      {
        unsigned hour = mainSplit[i++].toInt();
        t.setHMS(hour, t.minute(), t.second());
      }
    case 1:
      {
        unsigned minute = mainSplit[i].toInt();
        t.setHMS(t.hour(), minute, t.second());
      }
    case 0:
      t.setHMS(t.hour(), t.minute(), seconds);
      edt.setTime(t);
      break;
  }
  return edt.addSecs(-offset);
}
//Try both DateFormat values
ExtDate ExtDate::fromString( const QString& s )
{
	ExtDate dResult = ExtDate::fromString( s, Qt::TextDate );
	if ( dResult.isValid() ) return dResult;

	dResult = ExtDate::fromString( s, Qt::ISODate );
	if ( dResult.isValid() ) return dResult;
	else return ExtDate(); //invalid	
}
Exemplo n.º 3
0
ExtDate timeBox::createDate (bool */*ok*/)
{
	
	QString entry = text().stripWhiteSpace();

	// if entry is an empty string or invalid date use current date

	ExtDate date = ExtDate().fromString(entry);

	if ( !date.isValid() ) {
		kdDebug() << k_funcinfo << "Invalid date" << endl;
		showDate(ExtDate::currentDate());
		entry = text().stripWhiteSpace();
		return ExtDate::currentDate();
	} else {
		return date;
	}
}
Exemplo n.º 4
0
void
ExtDatePicker::dateChangedSlot(const ExtDate &date)
{
    kdDebug(298) << "ExtDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl;


//must remain commented unless ExtDate gets added to kdelibs
//    const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();

//    line->setText(KGlobal::locale()->formatDate(date, true));
		line->setText( date.toString( KGlobal::locale()->dateFormatShort() ) );
    selectMonth->setText(d->calendar->monthName(date, false));
    fillWeeksCombo(date);

    // calculate the item num in the week combo box; normalize selected day so as if 1.1. is the first day of the week
    ExtDate firstDay(date.year(), 1, 1);
    d->selectWeek->setCurrentItem((d->calendar->dayOfYear(date) + d->calendar->dayOfWeek(firstDay) - 2) / 7/*calendar->daysInWeek()*/);

    selectYear->setText(d->calendar->yearString(date, false));

    emit(dateChanged(date));
}
Exemplo n.º 5
0
bool
ExtDatePicker::setDate(const ExtDate& date)
{
    if(date.isValid())
    {
        table->setDate(date);  // this also emits dateChanged() which then calls our dateChangedSlot()
        return true;
    }
    else
    {
        kdDebug(298) << "ExtDatePicker::setDate: refusing to set invalid date." << endl;
        return false;
    }
}
int   ExtDate::daysTo( const ExtDate & a_date) const
{
	return a_date.jd() - jd();
}
Exemplo n.º 7
0
void modCalcAzel::processLines( QTextStream &istream ) {

	// we open the output file

//	QTextStream istream(&fIn);
	QString outputFileName;
	outputFileName = OutputLineEditBatch->text();
	QFile fOut( outputFileName );
	fOut.open(IO_WriteOnly);
	QTextStream ostream(&fOut);

	QString line;
	QString space = " ";
	int i = 0;
	long double jd0, jdf;
	dms LST;
	SkyPoint sp;
	dms raB, decB, latB, longB, azB, elB;
	double epoch0B;
	QTime utB;
	ExtDate dtB;

	while ( ! istream.eof() ) {
		line = istream.readLine();
		line.stripWhiteSpace();

		//Go through the line, looking for parameters

		QStringList fields = QStringList::split( " ", line );

		i = 0;

		// Read Ut and write in ostream if corresponds
		
		if(utCheckBatch->isChecked() ) {
			utB = QTime::fromString( fields[i] );
			i++;
		} else
			utB = utBoxBatch->time();
		
		if ( allRadioBatch->isChecked() )
			ostream << utB.toString() << space;
		else
			if(utCheckBatch->isChecked() )
				ostream << utB.toString() << space;
			
		// Read date and write in ostream if corresponds
		
		if(dateCheckBatch->isChecked() ) {
			 dtB = ExtDate::fromString( fields[i] );
			 i++;
		} else
			dtB = dateBoxBatch->date();
		if ( allRadioBatch->isChecked() )
			ostream << dtB.toString().append(space);
		else
			if(dateCheckBatch->isChecked() )
			 	ostream << dtB.toString().append(space);
		
		// Read Longitude and write in ostream if corresponds
		
		if (longCheckBatch->isChecked() ) {
			longB = dms::fromString( fields[i],TRUE);
			i++;
		} else
			longB = longBoxBatch->createDms(TRUE);
		
		if ( allRadioBatch->isChecked() )
			ostream << longB.toDMSString() << space;
		else
			if (longCheckBatch->isChecked() )
				ostream << longB.toDMSString() << space;
		
		// Read Latitude


		if (latCheckBatch->isChecked() ) {
			latB = dms::fromString( fields[i], TRUE);
			i++;
		} else
			latB = latBoxBatch->createDms(TRUE);
		if ( allRadioBatch->isChecked() )
			ostream << latB.toDMSString() << space;
		else
			if (latCheckBatch->isChecked() )
				ostream << latB.toDMSString() << space;
		
		// Read Epoch and write in ostream if corresponds
	
		if(epochCheckBatch->isChecked() ) {
			epoch0B = fields[i].toDouble();
			i++;
		} else
			epoch0B = getEpoch( epochBoxBatch->text() );

		if ( allRadioBatch->isChecked() )
			ostream << epoch0B << space;
		else
			if(epochCheckBatch->isChecked() )
				ostream << epoch0B << space;

		// We make the first calculations
		KStarsDateTime dt;
		dt.setFromEpoch( epoch0B );
		jdf = KStarsDateTime(dtB,utB).djd();
		jd0 = dt.djd();

		LST = KStarsDateTime(dtB,utB).gst().Degrees() + longB.Degrees();
		
		// Equatorial coordinates are the input coords.
		if (!horInputCoords) {
		// Read RA and write in ostream if corresponds

			if(raCheckBatch->isChecked() ) {
				raB = dms::fromString( fields[i],FALSE);
				i++;
			} else
				raB = raBoxBatch->createDms(FALSE);

			if ( allRadioBatch->isChecked() )
				ostream << raB.toHMSString() << space;
			else
				if(raCheckBatch->isChecked() )
					ostream << raB.toHMSString() << space;

			// Read DEC and write in ostream if corresponds

			if(decCheckBatch->isChecked() ) {
				decB = dms::fromString( fields[i], TRUE);
				i++;
			} else
				decB = decBoxBatch->createDms();

			if ( allRadioBatch->isChecked() )
				ostream << decB.toDMSString() << space;
			else
				if(decCheckBatch->isChecked() )
					ostream << decB.toDMSString() << space;

			sp = SkyPoint (raB, decB);
			sp.apparentCoord(jd0, jdf);
			sp.EquatorialToHorizontal( &LST, &latB );
			ostream << sp.az()->toDMSString() << space << sp.alt()->toDMSString() << endl;

		// Input coords are horizontal coordinates
		
		} else {
			if(azCheckBatch->isChecked() ) {
				azB = dms::fromString( fields[i],FALSE);
				i++;
			} else
				azB = azBoxBatch->createDms();

			if ( allRadioBatch->isChecked() )
				ostream << azB.toHMSString() << space;
			else
				if(raCheckBatch->isChecked() )
					ostream << azB.toHMSString() << space;

			// Read DEC and write in ostream if corresponds

			if(elCheckBatch->isChecked() ) {
				elB = dms::fromString( fields[i], TRUE);
				i++;
			} else
				elB = decBoxBatch->createDms();

			if ( allRadioBatch->isChecked() )
				ostream << elB.toDMSString() << space;
			else
				if(elCheckBatch->isChecked() )
					ostream << elB.toDMSString() << space;

			sp.setAz(azB);
			sp.setAlt(elB);
			sp.HorizontalToEquatorial( &LST, &latB );
			ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl;
		}

	}


	fOut.close();
}
Exemplo n.º 8
0
void timeBox::showDate (ExtDate t)
{
	setEntry( t.toString() );

}