void Taskmanager::setDay(Day &day, Day &dDay, string inputData)
{
	int size = inputData.size();

	string inputYear = inputData.substr(0, size - 4);
	string inputMonth = inputData.substr(size - 4, 2);
	string inputDate = inputData.substr(size - 2, 2);

	int year = atoi(inputYear.c_str());
	int month = atoi(inputMonth.c_str());
	int date = atoi(inputDate.c_str());

	if (date > day.getLastDay(month) || month > 12)
	{
		string error = "잘못된 날짜 입력";
		throw error;
	}

	day.setDay(year, month, date);

	if (isExistDDay)
	{
		setDDay(day, dDay);
	}
}
void Taskmanager::setDDay(Day &day, Day &dDay)
{
	isExistDDay = true;

	dDay.setDay(day.getYear(), day.getMonth(), day.getDate());

	if (oper == '+')
	{
		dDay += difference;
	}
	else
	{
		dDay -= difference;
	}
}
void Taskmanager::initializeDay(Day &day)
{
	time_t timeInfo;

	//struct tm *t;
	struct tm t;

	time(&timeInfo);
	//t = localtime(&timeInfo);
	localtime_s(&t, &timeInfo);

	int year = t.tm_year + 1900;		//1900기준이므로
	int month = t.tm_mon + 1;			//0월부터시작이므로
	int date = t.tm_mday;

	day.setDay(year, month, date);
}
Ejemplo n.º 4
0
Day HUEFile::read (bool saveData) {

    Options * opt =  Options::Instance();

    Day d;
    fstream stored;

    int col = opt->getColumnNumber();
    if (col > 4)
        column = col;     ////////////GUARDO LA COLUMNA QUE COGERE Y LUEGO USARÉ

    switch (column){	/////////////PONGO EL LIMITE PARA SUNRISE Y SUNSET
        case 4: sslimit = 9;
                break;
        case 5: sslimit = 0.9;
                break;
        case 6: sslimit = 0.3;
                break;
        case 7: sslimit = 0.1; ////NO TIENE UN LIMITE POR ABAJO
                break;
        case 8: sslimit = 0.1;
                break;
        case 9: sslimit = 10;
                break;
        case 10: sslimit = 20;
                break;
        case 11: sslimit = 30;
                break;
        case 12: sslimit = 15;
                break;
        case 13: sslimit = 0.1;
                break;
        case 14: sslimit = 0.1;
                break;
    }

    stored.open(ppath.c_str(), fstream::in);


    if (stored.good()) {
        //TODO: Improve these lines with "getline" command. Much easier to understand.

        float latitude, longitude;
        stored >> longitude >> latitude;
        Coordinates c;
        c.latitude = latitude;
        c.longitude = longitude;
        d.setRealCoordinates(c);


        string s;
        stored >> s;
        d.setStation (s);

        //The file pointer is moved to the day position.
        int day, moth;
        stored>>day>>moth;
        if (moth==3){//Si el mes es 3(marzo), cuento los 28 dias de febrero, y los 31 de enero
            day = day +28+31;
        }
        else if (moth<=7 && moth%2==0 && moth !=2){
            day = day + (moth/2)*31 + (moth/2-1)*30 + 28;//Si el mes es par antes de julio, cuento la mitad de meses 31, febrero con 28, y los demas con 30
        }
        else if (moth>7 && moth%2==0){
            day = day + (moth/2+1)*31 + (moth/2-2)*30 + 28;//Si el mes es par despues de julio, cuento la mitad mas 1 de meses 31(por agosto), febrero con 28, y los demas con 30
        }
        else if (moth<=7 && moth%2!=0 && moth !=1 && moth !=3){
            day = day + (moth/2-1)*30 + (moth/2+1)*31 + 28;
        }
        else if (moth>7 && moth%2!=0){
            day = day + (moth/2-1)*30 + (moth/2+1)*31 + 28;
        }
        else if (moth == 1){
            day = day;
        }
        else if (moth == 2){
            day = day + 31;
        }
        d.setDay(day);


        //The file pointer is moved to the year position.
        int year;
        stored >> year;
        d.setYear(year);


        stored >> elevation;

        float hour, min, seconds, auxvalues, transitions=0;
        float a;

        while(!stored.eof())
        {

            stored >> hour >> min >> seconds;

            hour = hour + min/60;
            hour = hour + seconds/3600;//pass seconds to hours

            times.push_back(hour);


            for (int i=4; i<column; i++){
                stored >> a;
            }

            stored >> auxvalues;
            values.push_back(auxvalues);


            for(int z=column; z<14; z++){
                stored >> a;
            }

        }


        File::setSkipFile(0);
        d.setTransitions(0);
        float sunrise = File::findSunrise(times, values);
        float sunset = File::findSunset(times, values);
        d.setSunrise(sunrise);
        d.setSunset(sunset);

        // Not saved by default (consumes time and a lot of memory).
        if (saveData) {
            d.setTimes (times);
            d.setValues (values);
        }


        if (opt->getConsoleOp() == true || opt->getFileReadedOp() == true){
            Console::validFiles (name, ppath, File::getSkipFile());
        }
        if (opt->getConsoleOp() == true){
            Console::placeInfo(d, values.size());
        }
        if (opt->getLoggerOp() == true){
            Logger::placeInfo(d, values.size());
            Logger::validFiles(name, ppath, File::getSkipFile(), d);//save in a file the number of valid files
        }

        return d;

    }