Exemplo n.º 1
0
//prints difference between stored date and present
void printDiff (State *s) {	
	s->next = NULL;
	FILE *in = fopen(makeFilePath(), "rb");
	if (in == NULL) {
		printf("No date stored. Try to store one by calling \"ctd -s [date]\"\n");
		return;
	}
	
	double jstored;
	fread(&jstored, sizeof(double), 1, in); 
	fclose(in);
	
	TDate *present = currentDate(NULL);
	
	double jpresent = toJulian(present);
	
	TDateDiff *diff = tdiff(jstored, jpresent);
	
	printDateDiff(diff);
	printf("\n");
	
	free(present);
	free(diff);

}
Exemplo n.º 2
0
void Logger::_UpdateFiles(bool bLevelChange)
{
	time_t t = g_pSM->GetAdjustedTime();
	tm *curtime = localtime(&t);

	if (!bLevelChange && curtime->tm_mday == m_Day)
	{
		return;
	}

	m_Day = curtime->tm_mday;

	char buff[PLATFORM_MAX_PATH];
	ke::SafeSprintf(buff, sizeof(buff), "%04d%02d%02d", curtime->tm_year + 1900, curtime->tm_mon + 1, curtime->tm_mday);

	ke::AString currentDate(buff);

	if (m_Mode == LoggingMode_PerMap)
	{
		if (bLevelChange)
		{
			for (size_t iter = 0; iter < static_cast<size_t>(-1); ++iter)
			{
				g_pSM->BuildPath(Path_SM, buff, sizeof(buff), "logs/L%s%u.log", currentDate.chars(), iter);
				if (!libsys->IsPathFile(buff))
				{
					break;
				}
			}
		}
		else
		{
			ke::SafeStrcpy(buff, sizeof(buff), m_NormalFileName.chars());
		}
	}
	else
	{
		g_pSM->BuildPath(Path_SM, buff, sizeof(buff), "logs/L%s.log", currentDate.chars());
	}

	if (m_NormalFileName.compare(buff))
	{
		_CloseNormal();
		m_NormalFileName = buff;
	}
	else
	{
		if (bLevelChange)
		{
			LogMessage("-------- Mapchange to %s --------", m_CurrentMapName.chars());
		}
	}

	g_pSM->BuildPath(Path_SM, buff, sizeof(buff), "logs/errors_%s.log", currentDate.chars());
	if (bLevelChange || m_ErrorFileName.compare(buff))
	{
		_CloseError();
		m_ErrorFileName = buff;
	}
}
Exemplo n.º 3
0
/**
 *\en
 * 	\brief Returns the number of days from this date to target (which is negative 
 * 	if target is earlier than this date). 
 *\_en
 * 	\brief Возвращает количество дней до указанной даты от даты, представленной объектом.
 * 
 * 	Возвращаемое значение может быть отрицательным, если указанная дата находится в прошлом по 
 * 	отношению к дате, представленной объектом.
 *\_ru
 */
int 		
aDateService::DaysTo ( const aDateService& target ) const
{
	QDate currentDate( Year(), Month(), Day() );
	QDate targetDate( target.Year(), target.Month(), target.Day() );
	return currentDate.daysTo( targetDate ) ;
}
Exemplo n.º 4
0
/**
 *\en
 * 	\brief Returns a aDateService object containing a date nyears later than the date of 
 * 	this object (or earlier if nyears is negative). 
 *\_en
 *\ru
 * 	\brief Возвращает объект класса aDateService содержащий дату на nyears лет позднее хранимой
 * 	в объекте даты (или ранее, если nyears меньше нуля).
 *\_ru
 */
aDateService*
aDateService::AddYears ( int nyears ) const
{
	QDate		currentDate( Year(), Month(), Day() );
	aDateService*	result = new aDateService( currentDate.addYears( nyears ) );

	return result;
}	
Exemplo n.º 5
0
uint16_t RTCDue::getYear ()
{
  _year = currentDate();
  
  uint32_t cent = BCD2BIN((_year & RTC_CALR_CENT_Msk) >> RTC_CALR_CENT_Pos);
  uint32_t year = BCD2BIN((_year & RTC_CALR_YEAR_Msk) >> RTC_CALR_YEAR_Pos);
  
  return (cent * seperator + year);
}
Exemplo n.º 6
0
int RTCDue::setMonth (int month)
{
  _day_of_week = calculateDayofWeek( getYear(), _month, getDay() );
  _day_of_week = BIN2BCD( _day_of_week ) << RTC_CALR_DAY_Pos;
  
  _changed = BIN2BCD( month ) << RTC_CALR_MONTH_Pos;
  
  _current_date = ( currentDate() & ~RTC_CALR_DAY_Msk & ~RTC_CALR_MONTH_Msk ) ^ ( _changed | _day_of_week );
  
  return (int)changeDate(_current_date);
}
Exemplo n.º 7
0
int RTCDue::setDay (int day)
{
  _day_of_week = calculateDayofWeek( getYear(), getMonth(), day );
  _day_of_week = BIN2BCD( _day_of_week ) << RTC_CALR_DAY_Pos;
  
  _changed = BIN2BCD( day ) << RTC_CALR_DATE_Pos;
  
  _current_date = ( currentDate() & ~RTC_CALR_DAY_Msk & ~RTC_CALR_DATE_Msk ) ^ ( _changed | _day_of_week );
  
  return (int)changeDate(_current_date);
}
Exemplo n.º 8
0
int RTCDue::setYear (uint16_t year)
{
  _day_of_week = calculateDayofWeek( year, getMonth(), getDay() );
  _day_of_week = BIN2BCD( _day_of_week ) << RTC_CALR_DAY_Pos;
  
  _changed = BIN2BCD( year / seperator ) << RTC_CALR_CENT_Pos | BIN2BCD( year % seperator ) << RTC_CALR_YEAR_Pos;
  
  _current_date = ( currentDate() & ~RTC_CALR_DAY_Msk & ~RTC_CALR_YEAR_Msk ) ^ ( _changed | _day_of_week );
  
  return (int)changeDate(_current_date);
}
Exemplo n.º 9
0
int RTCDue::isDateAlreadySet ()
{
  uint32_t dateregister;
  
  /* Get current RTC date */
  dateregister = currentDate ();
  
  if ( RESET_VALUE != dateregister )
    return 1;
  else
    return 0;
}
Exemplo n.º 10
0
	// Now
		// a static function that returns a MyDate object
		// initialized to the current date according to the system clock
	MyDate MyDate::Now() {
		// get time from system clock
		time_t rawtime;
		time(& rawtime);
		struct tm * timeinfo;
		timeinfo = localtime(& rawtime);

		// plug it into a MyDate object
		MyDate currentDate(timeinfo->tm_mday, (timeinfo->tm_mon + 1), (timeinfo->tm_year + 1900));

		return currentDate;
	}
Exemplo n.º 11
0
string customerLog::now(){
    time_t t;
    struct tm * now;
    char buffer[80];

    t = time(&t);
    now = localtime(&t);
    strftime(buffer, 80, "%d-%m-%Y %I:%M:%S", now);
    std::string currentDate(buffer);

    return currentDate;
}
Exemplo n.º 12
0
//prints a live countdown relative to given date
void printCountdown (State *s) {
	s->next = NULL;
	
	TDate *date = parse(s->argv[2]);
	if (!date) {
		printf("Could not parse date. Check formatting\n");
		return;
	}
	
	TDate *now = currentDate(NULL);
	
	countdown (toJulian(now), toJulian(date));	
}
std::string JSCLanguageBase::generateLicenceHeader(std::string filename) const {
  static const std::string sFileNameKey = "{FILE_NAME}";
  static const std::string sDateKey = "{DATE}";
  std::string result = m_licenceHeader;

  auto foundIndex = std::string::npos;

  while (std::string::npos != (foundIndex = result.find(sFileNameKey))) {
    result.replace(foundIndex, sFileNameKey.size(), filename);
  }

  while (std::string::npos != (foundIndex = result.find(sDateKey))) {
    result.replace(foundIndex, sDateKey.size(), currentDate());
  }

  return result + '\n';
}
Exemplo n.º 14
0
//prints a live countdown relative to stored date
void printCountdownStored (State *s) {
	s->next = NULL;
	
	FILE *in = fopen(makeFilePath(), "rb");
	if (!in) {
		printf("No date stored. Try to store one by calling \"ctd -s [date]\"\n");
		return;
	}
	
	double jdate;
	fread(&jdate, sizeof(double), 1, in);
	fclose(in); 
	
	TDate *now = currentDate(NULL);
	double jnow = toJulian(now);
	
	countdown (jnow, jdate);	
}
Exemplo n.º 15
0
float student::calcAmountOwed(){
    boost::gregorian::date currentDate(student::firstEntryDate());
    boost::gregorian::date endDate(studentBill[student::numberEntries()-1].getDate());
    float monthTotal=0.0;
    float overallTotal=0.0;
    for(int index=0; index<student::numberEntries();){
        bool currentEntryInMonth = entryInMonth(studentBill[index],currentDate);
        if(currentEntryInMonth == true){
            monthTotal += studentBill[index].getAmount(); 
            index++;
        }
        else {
            currentDate = startOfNextMonth(currentDate);
            overallTotal = monthTotal+overallTotal+(overallTotal*.01);
            monthTotal=0.0;
        }
    }
    return (overallTotal=monthTotal+overallTotal+(overallTotal*.01));
}  
Exemplo n.º 16
0
void FilterDateOrderWidget::populate()
{
    QDate date = QDate::currentDate().addDays(PLUS_DAYS);
    if (m_currentIndex != -1) {
        date = currentDate();
    }

    m_currentIndex = -1;

    m_quickDates.clear();

    QSqlQuery sql;
    sql.exec(QString("SELECT mo_date FROM manufacture_orders "
                     "WHERE mo_state <> %1 AND mo_station = %2 AND "
                     "mo_date >= CURRENT_DATE "
                     "GROUP BY mo_date")
             .arg(ManufactureOrder::CompletedState)
             .arg(m_station->id()));

    if (sql.lastError().isValid()) {
        qCritical() << sql.lastError();
        QMessageBox::critical(this, "Error", sql.lastError().text());
        return;
    }

    while(sql.next()) {
        m_quickDates.append(sql.value(0).toDate());
    }

    if (m_quickDates.isEmpty()) {
        return;
    }

    qSort(m_quickDates);

    if (m_quickDates.contains(date)) {
        setCurrentDate(date);
    } else {
        setCurrentDate(m_quickDates.last());
    }

}
Exemplo n.º 17
0
void Logger::log(string msg) {
  string filename = LOG_DIRECTORY + name_prefix + currentDate() + ".log";
  vector <string> messages = split(msg, '\n');

  pthread_mutex_lock(&log_mutex);

  FILE * fp = fopen(filename.c_str(), "a");
  while (fp == NULL) {
    usleep(50000);
    fp = fopen(filename.c_str(), "a");
  }

  string id = identifier.find(pthread_self()) == identifier.end() ?
      "Main" : identifier[pthread_self()];
  for (vector <string>::iterator it = messages.begin(); it != messages.end();
      ++it) {
    fprintf(fp, "%s %s[%llu]: %s\n", currentDateTime().c_str(), id.c_str(),
            (unsigned long long) pthread_self() % 10000, it -> c_str());
  }

  fclose(fp);

  pthread_mutex_unlock(&log_mutex);
}
	// register an interpolated curve object
DLLEXPORT char * xlInitiateInterpolatedCurve(const char * objectID_       ,
                                             xloper     * calculationDate_,
                                             const char * curveCalendarId_,
                                             xloper     * helperId_       ,
                                             xloper     * trigger_         ) {
    
    boost::shared_ptr<ObjectHandler::FunctionCall> functionCall(
        new ObjectHandler::FunctionCall("xlInitiateInterpolatedCurve")) ;

    try {

        QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ;

            // range validation
        ObjectHandler::validateRange(trigger_        , "trigger"         );
        ObjectHandler::validateRange(helperId_       , "helper Id"       );
        ObjectHandler::validateRange(calculationDate_, "calculation Date");
            
        ObjectHandler::ConvertOper myOper1(* calculationDate_) ;	// xlopers

        std::vector<std::string> helperId = ObjectHandler::operToVector<std::string>(
            * helperId_, "helper Id") ;

        QuantLib::Date currentDate(									// initiate pricing date
            myOper1.missing() ? 
            QuantLib::Date() : 
            QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper1)));

        std::vector<boost::shared_ptr<QuantLib::BootstrapHelper<	// the helpers
			QuantLib::YieldTermStructure> > > helpers;

        for (std::vector<std::string>::const_iterator It = helperId.begin();
			It != helperId.end(); ++It) {

            OH_GET_REFERENCE(helperPtr, * It,						// get helper references
                             QuantLibAddin::RateHelper, 
                             QuantLib::RateHelper);

			helpers.push_back(helperPtr);

        }

            // Construction du value object
        boost::shared_ptr<QuantLibAddin::ValueObjects::interpolatedCurveValueObject> curveValueObject(
            new QuantLibAddin::ValueObjects::interpolatedCurveValueObject(
                objectID_,
                currentDate.serialNumber(),
                true)) ;

            // creates the curve
        boost::shared_ptr<ObjectHandler::Object> myCurve(
            new QuantLibAddin::interpolatedCurveObject(
				curveValueObject,
                currentDate,
				helpers, true,
                std::vector<QuantLib::Handle<QuantLib::Quote> >(),	// empty jump date
                std::vector<QuantLib::Date>(),
                CURVE_DEFAULT_ACCURACY));

		    // object storage
	    std::string returnValue =
            ObjectHandler::RepositoryXL::instance().storeObject(objectID_, 
                                                                myCurve, 
                                                                true);

        static char ret[XL_MAX_STR_LEN] ;
        ObjectHandler::stringToChar(returnValue, ret);
        return ret;

    } catch (std::exception & e) {

        static char ret[XL_MAX_STR_LEN];
        ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall);
        ObjectHandler::stringToChar(e.what(), ret);
        return ret;

    }

} ;
Exemplo n.º 19
0
void AppointmentPicker::viewMonth()
{
    viewMonth( currentDate() );
}
Exemplo n.º 20
0
void AppointmentPicker::viewDay()
{
    viewDay( currentDate() );
}
Exemplo n.º 21
0
/**
 *\en
 * 	\brief Returns the number of days from this date to target (which is negative 
 * 	if target is earlier than this date). 
 *\_en
 * 	\brief Возвращает количество дней до указанной даты от даты, представленной объектом.
 * 
 * 	Возвращаемое значение может быть отрицательным, если указанная дата находится в прошлом по 
 * 	отношению к дате, представленной объектом.
 *\_ru
 */
int 		
aDateService::DaysTo ( const QDate& target )  const
{
	QDate currentDate( Year(), Month(), Day() );
	return currentDate.daysTo( target ) ;
}
Exemplo n.º 22
0
int RTCDue::getMonth ()
{
  _month = currentDate();
  
  return BCD2BIN((_month & RTC_CALR_MONTH_Msk) >> RTC_CALR_MONTH_Pos);
}
Exemplo n.º 23
0
void MSMBSDate::setToday(void)
{
  _date = currentDate();
  changed();
}
Exemplo n.º 24
0
void Ajout::on_b_valider_clicked()
{
    MainWindow* parent = qobject_cast<MainWindow*>(this->parent());
    if (parent == 0) { return; }

    if((ui->q_nbPieces->value() == 0)
            || (ui->q_superficieTerrain->value() == 0)
            || (ui->q_adresse->text() == "")
            || (ui->q_ville->text() == "")
            || (ui->q_codePostal->text() == "")
            || (ui->q_description->toPlainText() == "")
            || (ui->q_prix->value() == 0))
    {
        QMessageBox::information(this, "Validation impossible", "Certains champs n'ont pas été remplis correctement");
        if(ui->q_nbPieces->value() == 0) {
            QPalette palette = ui->l_nbPieces->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_nbPieces->setPalette(palette);
        } else {
            QPalette palette = ui->l_nbPieces->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_nbPieces->setPalette(palette);
        }

        if(ui->q_superficieTerrain->value() == 0) {
            QPalette palette = ui->l_superficieTerrain->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_superficieTerrain->setPalette(palette);
        } else {
            QPalette palette = ui->l_superficieTerrain->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_superficieTerrain->setPalette(palette);
        }

        if(ui->q_adresse->text() == "") {
            QPalette palette = ui->l_adresse->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_adresse->setPalette(palette);
        } else {
            QPalette palette = ui->l_adresse->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_adresse->setPalette(palette);
        }

        if(ui->q_ville->text() == "") {
            QPalette palette = ui->l_ville->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_ville->setPalette(palette);
        } else {
            QPalette palette = ui->l_ville->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_ville->setPalette(palette);
        }

        if(ui->q_codePostal->text() == "") {
            QPalette palette = ui->q_codePostal->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->q_codePostal->setPalette(palette);
        } else {
            QPalette palette = ui->q_codePostal->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->q_codePostal->setPalette(palette);
        }

        if(ui->q_description->toPlainText() == "") {
            QPalette palette = ui->l_description->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_description->setPalette(palette);
        } else {
            QPalette palette = ui->l_description->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_description->setPalette(palette);
        }

        if(ui->q_prix->value() == 0) {
            QPalette palette = ui->l_prix->palette();
            QBrush brush(QColor(255, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_prix->setPalette(palette);
        } else {
            QPalette palette = ui->l_prix->palette();
            QBrush brush(QColor(0, 0, 0, 255));
            brush.setStyle(Qt::SolidPattern);
            palette.setBrush(QPalette::Active, QPalette::WindowText, brush);
            ui->l_prix->setPalette(palette);
        }
    }
    else
    {
        QList<QString> ps;
        for(int i=0;i<ui->listWidget->count();i++)
        {
            QList<QString> file = ui->listWidget->item(i)->text().split('/');

            QString filePath ="../../../../BestResidence/Photos/"+file.value(file.length()-1);
            QFile::copy(ui->listWidget->item(i)->text(),filePath);
            ps.append(filePath);
        }

        Client* prop;
        for(int i=0;i<parent->clients.length();i++)
        {
            if(parent->clients.value(i)->getId() == ui->q_client->currentData().toString())
            {
                prop = parent->clients.value(i);
            }
        }
        QList<QString> file = ui->l_photoPrincipal->text().split('/');

        QString filePath ="../../../../BestResidence/Photos/"+file.value(file.length()-1);
        QFile::copy(ui->l_photoPrincipal->text(),filePath);
        if(modif == 0)
        {
            QString date = QString::fromStdString(currentDate());

            Annonce* a = new Annonce(ui->q_typeAnnonce->currentText(), ui->q_typeBien->currentText(), ui->q_nbPieces->value(), ui->q_superficieTerrain->value(), ui->q_adresse->text(), ui->q_ville->text(), ui->q_codePostal->text(), ui->q_description->toPlainText(), ui->q_prix->value(), QDate::fromString(date, "dd-MM-yyyy"), filePath, ps, 0, prop, NULL);
            parent->annonces.append(a);
            prop->setNbContrats(prop->getNbContrats()+1);
        }
        else
        {
            ann_a_modif->setTypeAnnonce(ui->q_typeAnnonce->currentText());
            ann_a_modif->setTypeBien(ui->q_typeBien->currentText());
            ann_a_modif->setNbPieces(ui->q_nbPieces->value());
            ann_a_modif->setSuperficie(ui->q_superficieTerrain->value());
            ann_a_modif->setAdresse(ui->q_adresse->text());
            ann_a_modif->setVille(ui->q_ville->text());
            ann_a_modif->setCodePostal(ui->q_codePostal->text());
            ann_a_modif->setDescription(ui->q_description->toPlainText());
            ann_a_modif->setPrix(ui->q_prix->value());
            ann_a_modif->setPhotoPrincipale(filePath);
            ann_a_modif->setPhotosSupp(ps);
            ann_a_modif->setProp(prop);
        }

        parent->setAnnule(false);
        this->close();
    }
}
Exemplo n.º 25
0
EU3Tech::EU3Tech(common::date startDate, Object* mainObj, Object* governmentObj, Object* productionObj,
                 Object* tradeObj, Object* navalObj, Object* landObj)
{
	vector<IObject*> groupsObjs = mainObj->getValue("groups")[0]->getLeaves();
	for(vector<IObject*>::iterator groupItr = groupsObjs.begin(); groupItr != groupsObjs.end(); groupItr++)
	{
		string	name			= (*groupItr)->getKey();
		int		startLevel	= atoi( (*groupItr)->getLeaf("start_level").c_str() );
		double	modifier		= atof( (*groupItr)->getLeaf("modifier").c_str() );
		groups.insert(make_pair(name, make_pair(startLevel, modifier) ));
	}

	vector<IObject*> governmentObjs = governmentObj->getLeaves();
	governmentYears.resize(governmentObjs.size());
	for (vector<IObject*>::iterator techItr = governmentObjs.begin(); techItr != governmentObjs.end(); techItr++)
	{
		int level	= atoi( (*techItr)->getLeaf("id").c_str() );
		int year		= atoi( (*techItr)->getLeaf("average_year").c_str() );
		governmentYears[level] = year;
	}

	vector<IObject*> productionObjs = productionObj->getLeaves();
	productionYears.resize(productionObjs.size());
	for (vector<IObject*>::iterator techItr = productionObjs.begin(); techItr != productionObjs.end(); techItr++)
	{
		int level	= atoi( (*techItr)->getLeaf("id").c_str() );
		int year		= atoi( (*techItr)->getLeaf("average_year").c_str() );
		productionYears[level] = year;
	}

	vector<IObject*> tradeObjs = tradeObj->getLeaves();
	tradeYears.resize(tradeObjs.size());
	for (vector<IObject*>::iterator techItr = tradeObjs.begin(); techItr != tradeObjs.end(); techItr++)
	{
		int level	= atoi( (*techItr)->getLeaf("id").c_str() );
		int year		= atoi( (*techItr)->getLeaf("average_year").c_str() );
		tradeYears[level] = year;
	}

	vector<IObject*> navalObjs = navalObj->getLeaves();
	navalYears.resize(navalObjs.size());
	for (vector<IObject*>::iterator techItr = navalObjs.begin(); techItr != navalObjs.end(); techItr++)
	{
		int level	= atoi( (*techItr)->getLeaf("id").c_str() );
		int year		= atoi( (*techItr)->getLeaf("average_year").c_str() );
		navalYears[level] = year;
	}

	vector<IObject*> landObjs = landObj->getLeaves();
	landYears.resize(landObjs.size());
	for (vector<IObject*>::iterator techItr = landObjs.begin(); techItr != landObjs.end(); techItr++)
	{
		int level	= atoi( (*techItr)->getLeaf("id").c_str() );
		int year		= atoi( (*techItr)->getLeaf("average_year").c_str() );
		landYears[level] = year;
	}

	for (map<string, pair<int, double> >::iterator groupsItr = groups.begin(); groupsItr != groups.end(); groupsItr++)
	{
		vector<double> startingLevels;
		startingLevels.resize(5);

		double	rate			= groupsItr->second.second;

		double	level			= groupsItr->second.first;
		int		nextLevel	= groupsItr->second.first + 1;
		common::date		currentDate("1399.2.1");
		int		yearCurrentTech	= governmentYears[nextLevel - 1];
		int		yearNextTech		= governmentYears[nextLevel];
		while (currentDate < startDate)
		{
			level += (rate / 12) / (yearNextTech - yearCurrentTech);
			if (level >= nextLevel)
			{
				yearCurrentTech	= governmentYears[nextLevel];
				nextLevel++;
				yearNextTech		= governmentYears[nextLevel];
			}

			currentDate.month++;
			if (currentDate.month > 12)
			{
				currentDate.year++;
				currentDate.month -= 12;
			}
		}
		startingLevels[GOVERNMENT] = level;

		level					= groupsItr->second.first;
		nextLevel			= groupsItr->second.first + 1;
		currentDate			= common::date("1399.2.1");
		yearCurrentTech	= productionYears[nextLevel - 1];
		yearNextTech		= productionYears[nextLevel];
		while (currentDate < startDate)
		{
			level += (rate / 12) / (yearNextTech - yearCurrentTech);
			if (level >= nextLevel)
			{
				yearCurrentTech	= productionYears[nextLevel];
				nextLevel++;
				yearNextTech		= productionYears[nextLevel];
			}

			currentDate.month++;
			if (currentDate.month > 12)
			{
				currentDate.year++;
				currentDate.month -= 12;
			}
		}
		startingLevels[PRODUCTION] = level;

		level					= groupsItr->second.first;
		nextLevel			= groupsItr->second.first + 1;
		currentDate			= common::date("1399.2.1");
		yearCurrentTech	= tradeYears[nextLevel - 1];
		yearNextTech		= tradeYears[nextLevel];
		while (currentDate < startDate)
		{
			level += (rate / 12) / (yearNextTech - yearCurrentTech);
			if (level >= nextLevel)
			{
				yearCurrentTech	= tradeYears[nextLevel];
				nextLevel++;
				yearNextTech		= tradeYears[nextLevel];
			}

			currentDate.month++;
			if (currentDate.month > 12)
			{
				currentDate.year++;
				currentDate.month -= 12;
			}
		}
		startingLevels[TRADE] = level;

		level					= groupsItr->second.first;
		nextLevel			= groupsItr->second.first + 1;
		currentDate			= common::date("1399.2.1");
		yearCurrentTech	= navalYears[nextLevel - 1];
		yearNextTech		= navalYears[nextLevel];
		while (currentDate < startDate)
		{
			level += (rate / 12) / (yearNextTech - yearCurrentTech);
			if (level >= nextLevel)
			{
				yearCurrentTech	= navalYears[nextLevel];
				nextLevel++;
				yearNextTech		= navalYears[nextLevel];
			}

			currentDate.month++;
			if (currentDate.month > 12)
			{
				currentDate.year++;
				currentDate.month -= 12;
			}
		}
		startingLevels[NAVAL] = level;

		level					= groupsItr->second.first;
		nextLevel			= groupsItr->second.first + 1;
		currentDate			= common::date("1399.2.1");
		yearCurrentTech	= landYears[nextLevel - 1];
		yearNextTech		= landYears[nextLevel];
		while (currentDate < startDate)
		{
			level += (rate / 12) / (yearNextTech - yearCurrentTech);
			if (level >= nextLevel)
			{
				yearCurrentTech	= landYears[nextLevel];
				nextLevel++;
				yearNextTech		= landYears[nextLevel];
			}

			currentDate.month++;
			if (currentDate.month > 12)
			{
				currentDate.year++;
				currentDate.month -= 12;
			}
		}
		startingLevels[LAND] = level;

		startingTechLevels.insert(make_pair(groupsItr->first, startingLevels));
	}
}
Exemplo n.º 26
0
 //Method to select dates, if date selection is enabled.
 void MonthView::SelectDates(int row, int column)
         {
                 if(!EnableDateSelection)
                 {
                         return;
                 }

                 QDate currentDate(QDate :: fromString(ui->tblDates->item(row,column)->whatsThis()));
                 //For Start day control
                 if(IsStartDate)
                 {
                         int currentCol = column;
                         if(currentDate <= EndDate)
                         {
                                 int colEnd = 7;
                                 for(int r = row; r <= rowEndDate; r++)
                                 {
                                         if(r == rowEndDate)
                                         {
                                                 colEnd = colEndDate;
                                         }
                                         if(r > row)
                                         {
                                                 currentCol = 1;
                                         }

                                         if(r == row)
                                         {
                                                 currentCol = column;
                                         }

                                         for(int c = currentCol; c <= colEnd; c++)
                                         {
                                                 if(!ui->tblDates->item(r,c)->isSelected())
                                                 {
                                                         ui->tblDates->setItemSelected(ui->tblDates->item(r,c),true);
                                                 }
                                         }

                                 }
                         }
                         else
                         {
                                 ui->tblDates->selectedItems().clear();
                                 this->setEndDate(currentDate);
                                 rowEndDate  = row;
                                 colEndDate = column;
                                 ui->tblDates->setItemSelected(ui->tblDates ->item(row,column),true);
                         }

                         this->setStartDate(currentDate);
                         rowStartDate = row;
                         colStartDate = column;

                 }
                 else
                 {
                         //Return if end date is invalid
                         if(this->EndDate.isValid())
                         {
                                 int currentCol = colStartDate;
                                 if(currentDate >= StartDate)
                                 {
                                         int colEnd = 7;
                                         for(int r = rowStartDate; r <= row; r++)
                                         {
                                                 if(r == row)
                                                 {
                                                         colEnd = column ;
                                                 }
                                                 if(r > rowStartDate)
                                                 {
                                                         currentCol = 1;
                                                 }

                                                 if(r == rowStartDate)
                                                 {
                                                         currentCol = colStartDate ;
                                                 }

                                                 for(int c = currentCol; c <= colEnd; c++)
                                                 {
                                                         if(!ui->tblDates->item(r,c)->isSelected())
                                                         {
                                                                 ui->tblDates->setItemSelected(ui->tblDates->item(r,c),true);
                                                         }
                                                 }

                                         }
                                 }
                                 else
                                 {
                                         ui->tblDates->selectedItems().clear();

                                         this->StartDate = currentDate;
                                         rowStartDate  = rowEndDate = row;
                                         colStartDate = colEndDate = column;
                                         ui->tblDates->setItemSelected(ui->tblDates ->item(row,column),true);
                                 }
                                         this->setEndDate(currentDate);
                                         rowEndDate = row;
                                         colEndDate = column;
                         }
                 }
         }
Exemplo n.º 27
0
int RTCDue::getDay ()
{
  _day = currentDate();
  
  return BCD2BIN((_day & RTC_CALR_DATE_Msk) >> RTC_CALR_DATE_Pos);
}
Exemplo n.º 28
0
int RTCDue::getDayofWeek ()
{
  _day_of_week = currentDate();
  
  return BCD2BIN((_day_of_week & RTC_CALR_DAY_Msk) >> RTC_CALR_DAY_Pos) - 1;
}
Exemplo n.º 29
0
DateTimeInfo::DateTimeInfo()
{
    cDate = currentDate();
    cTime = currentTime();
    cTimezone = currentTimezone();
}