Exemple #1
0
 bool CDateTime::SetDate(UINT32 year, UINT32 month, UINT32 day)
 {
     if (!(year >= 1970 && year <= 2037) || \
         !(month >= 1 && month <= 12) || \
         !(day >= 1 && day <= 31)) {
             return false;
     }
     time_t rawtime;
     struct tm timeinfo;
     time(&rawtime);
     localtime_s(&timeinfo,&rawtime);
     timeinfo.tm_year = year - 1900;
     timeinfo.tm_mon = month-1;
     timeinfo.tm_mday = day;
     timeinfo.tm_hour = m_time.tm_hour;
     timeinfo.tm_min = m_time.tm_min;
     timeinfo.tm_sec = m_time.tm_sec;
      
     rawtime = mktime(&timeinfo);
     SetTimeValue(rawtime);
     return true;
 }
void VHTTPServerLog::_CalculateNextFileRotationTime()
{
	fNextFileRotationTime.Clear();

	if (fBackupSettings.RotateOnSchedule())
	{
		XBOX::VTime		curTime;
		XBOX::VDuration tempDuration;
		XBOX::VFilePath logPath;

		_GetLogFilePath (logPath);
		fNextFileRotationTime.FromSystemTime();
		curTime.FromSystemTime();

		if (GetFileCreationTime (logPath, &fLastFileRotationTime) != XBOX::VE_OK)
		{
			fLastFileRotationTime.FromSystemTime();
			fLastFileRotationTime.AddDays (-1);
		}

		switch (fBackupSettings.GetLogRotationMode())
		{
			case LRC_NO_ROTATION:
			case LRC_ROTATE_ON_FILE_SIZE:
				fNextFileRotationTime.Clear();
				break;
				
			case LRC_ROTATE_EVERY_HOUR:
			{				
				// I will first get the date of the last backup, or the creation date
				fNextFileRotationTime = fLastFileRotationTime;	
				
				
				// if the date (dd/mm/yy) is different from the curent date, we have to backup to the current date
				if ((fNextFileRotationTime.GetLocalDay()!=curTime.GetLocalDay())||(fNextFileRotationTime.GetLocalMonth()!=curTime.GetLocalMonth())||(fNextFileRotationTime.GetLocalYear()!=curTime.GetLocalYear()))
				{
					// we use the date of today 
					fNextFileRotationTime.FromSystemTime();	
				}
				
				// set the time to the "starting at" value
				SetTimeValue (fNextFileRotationTime, fBackupSettings.GetStartingTime());

				while(fNextFileRotationTime <= fLastFileRotationTime)
				{
					fNextFileRotationTime.AddHours( fBackupSettings.GetFrequency());
				}
				
				if ((fNextFileRotationTime.GetLocalDay()!=curTime.GetLocalDay())||(fNextFileRotationTime.GetLocalMonth()!=curTime.GetLocalMonth())||(fNextFileRotationTime.GetLocalYear()!=curTime.GetLocalYear()))
				{
					// set the time to the "starting at" value
					SetTimeValue (fNextFileRotationTime, fBackupSettings.GetStartingTime());
				}
				break;	// LRC_ROTATE_EVERY_HOUR
			}

			case LRC_ROTATE_EVERY_DAY:
			{
				// I will first get the date of the last backup, or the creation date
				fNextFileRotationTime = fLastFileRotationTime;
				fNextFileRotationTime.AddDays (fBackupSettings.GetFrequency());

				// set the time to the "starting at" value
				SetTimeValue (fNextFileRotationTime, fBackupSettings.GetStartingTime());

				break;	// LRC_ROTATE_EVERY_DAY
			}
				
			case LRC_ROTATE_EVERY_WEEK:
			{
				sLONG dayHour = 0;
				//	First, we check if there is a backup today
				//	Then if there is one this week				
				
				// I will first get the date of the last backup, or the creation date
				fNextFileRotationTime = fLastFileRotationTime;	
				// if the date is the date of today, we just update the hour
				if ((fNextFileRotationTime.GetLocalDay()==curTime.GetLocalDay())&&(fNextFileRotationTime.GetLocalMonth()==curTime.GetLocalMonth())&&(fNextFileRotationTime.GetLocalYear()==curTime.GetLocalYear()))
				{
					VHTTPServerLogBackupSettings::EWeekDay weekDay = (VHTTPServerLogBackupSettings::EWeekDay)curTime.GetWeekDay();

					if (fBackupSettings.GetSaveOnWeekDay (weekDay))
					{	
						dayHour = fBackupSettings.GetWeekDayBackupHour (weekDay);
						
						SetTimeValue (fNextFileRotationTime, dayHour);
					}

					if (fLastFileRotationTime < fNextFileRotationTime)
					{
						break;	// we will have to backup later this day
					}
				}
				// no backup time has been determined
				// let's search the next day which has a backup planned
				
				bool flagIsOk = false;
				fNextFileRotationTime = fLastFileRotationTime;	
				//	This week a backup is planned... because a backup has been done already
				//	Let's check if another backup is planned this week
				//	note : like in the database backup, if we missed one backup, it will be done ASAP
				if (fNextFileRotationTime.GetWeekDay() != VHTTPServerLogBackupSettings::eSunday)
				{
					while (fNextFileRotationTime.GetWeekDay() != VHTTPServerLogBackupSettings::eSunday  && !flagIsOk)
					{
						VHTTPServerLogBackupSettings::EWeekDay weekDay = (VHTTPServerLogBackupSettings::EWeekDay)fNextFileRotationTime.GetWeekDay();

						fNextFileRotationTime.AddDays (1);		// check the next day

						if (fBackupSettings.GetSaveOnWeekDay (weekDay))
						{
							dayHour = fBackupSettings.GetWeekDayBackupHour (weekDay);
							
							SetTimeValue (fNextFileRotationTime, dayHour);
							flagIsOk = true;
						}
					}
				}

				if (flagIsOk)	// another backup has been planned
					break;
				
				//	There is no backup to do this week
				//	Let's look gEveryWeek after ...
				fNextFileRotationTime = fLastFileRotationTime;	
				fNextFileRotationTime.AddDays (fBackupSettings.GetFrequency() * 7);

				//	We "rewind" the week until the first day of the week : Monday !
				while (fNextFileRotationTime.GetWeekDay() != VHTTPServerLogBackupSettings::eMonday)
					fNextFileRotationTime.AddDays(-1);

				//	We look each day of the week
				if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eMonday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eMonday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
				}
				else if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eTuesday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eTuesday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
					
					fNextFileRotationTime.AddDays(1);
				}
				else if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eWednesday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eWednesday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
					
					fNextFileRotationTime.AddDays(2);
				}
				else if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eThursday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eThursday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
					
					fNextFileRotationTime.AddDays(3);
					
				}
				else if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eFriday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eFriday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
					
					fNextFileRotationTime.AddDays(4);
				}
				else if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eSaturday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eSaturday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
					
					fNextFileRotationTime.AddDays(5);
				}
				else if (fBackupSettings.GetSaveOnWeekDay (VHTTPServerLogBackupSettings::eSunday))
				{
					dayHour = fBackupSettings.GetWeekDayBackupHour (VHTTPServerLogBackupSettings::eSunday);
					
					SetTimeValue (fNextFileRotationTime, dayHour);
					
					fNextFileRotationTime.AddDays(6);
				}

				break; // LRC_ROTATE_EVERY_WEEK
			}

			case LRC_ROTATE_EVERY_MONTH:
			{	
				fNextFileRotationTime = fLastFileRotationTime;
				fNextFileRotationTime.AddMonths( fBackupSettings.GetFrequency());
				
				if (fBackupSettings.GetMonthDay() == 29)	// the preference selected is "Last"
				{
					fNextFileRotationTime.AddMonths(1);
					fNextFileRotationTime.SetLocalDay(1);	// sets the time to the first day of he month
					fNextFileRotationTime.AddDays(-1);		// removes one day to get the last day of the previous month
				}
				else
				{
					fNextFileRotationTime.SetLocalDay(fBackupSettings.GetMonthDay());
				}
				// set the time to the "starting at" value
				SetTimeValue (fNextFileRotationTime, fBackupSettings.GetMonthDayHour());

				break;	// LRC_ROTATE_EVERY_MONTH
			}
				
			default : // Trying to backup on an unknown schedule
				assert (false);
				break;
		}
	}
}
void CMyDateEdit::SetDetectText(CString strText)
{
	CString strYear,strMonth,strDay,strHour,strMin,strSec;
	COleDateTime tm;
	int i=-1;
	int Year;
	BOOL Leap=FALSE;
	if(m_isDate && strText.GetLength()>=10)
	{
		strYear=strText.Mid(0,4);
		strMonth=strText.Mid(5,2);
		strDay=strText.Mid(8,2);
		strHour="00";
		strMin="00";
		strSec="00";
	}
	if(m_isDateTime && strText.GetLength()>=19)
	{
		strYear=strText.Mid(0,4);
		strMonth=strText.Mid(5,2);
		strDay=strText.Mid(8,2);
		strHour=strText.Mid(11,2);
		strMin=strText.Mid(14,2);
		strSec=strText.Mid(17,2);
	}
	if(m_isTime&& strText.GetLength()>=8)
	{
		strYear="1960";
		strMonth="01";
		strDay="01";
		strHour=strText.Mid(0,2);
		strMin=strText.Mid(3,2);
		strSec=strText.Mid(6,7);
	}
	if(atoi(strYear)<1900 ||atoi(strYear)>2100) strYear="1900";
	if(atoi(strMonth)>12||atoi(strMonth)<1) strMonth="01";
	if(atoi(strDay)>31||atoi(strDay)<1) strDay="01";
	if(atoi(strHour)>23||atoi(strHour)<0) strHour="00";
	if(atoi(strMin)>59||atoi(strMin)<0) strMin="00";
	if(atoi(strSec)>59||atoi(strSec)<0) strSec="00";
	Year=atoi(strYear);
	if((Year%4)==0)
	{
		if(((Year%100)==0)&&((Year%400)!=0))
			Leap=FALSE;
		else
			Leap=TRUE;
	}
	else
		Leap=FALSE;
	if(atoi(strMonth)==1||atoi(strMonth)==3||atoi(strMonth)==5||atoi(strMonth)==7
		||atoi(strMonth)==8||atoi(strMonth)==10||atoi(strMonth)==12)
		strDay=atoi(strDay)>31?"31":strDay;
	if(atoi(strMonth)==4||atoi(strMonth)==6||atoi(strMonth)==9||atoi(strMonth)==11)
		strDay=atoi(strDay)>30?"30":strDay;
	if(atoi(strMonth)==2)
	{
		if(Leap)
			strDay=atoi(strDay)>29?"29":strDay;
		else
			strDay=atoi(strDay)>28?"28":strDay;
	}
	i=tm.SetDateTime(atoi(strYear),atoi(strMonth),atoi(strDay),atoi(strHour),atoi(strMin),atoi(strSec));
	if(i==0)
	{
		SetTimeValue(tm);
		return;
	}
	else
	{
		SetDefault();
	}
}
void CBatchSetCardAccess::on_btnForbidden_clicked( )
{
    SetTimeValue( false );
}
void CBatchSetCardAccess::on_btnAllTime_clicked( )
{
    SetTimeValue( true );
}
Exemple #6
0
 CDateTime & CDateTime::DecWeek(UINT32 week)
 {
     time_t tmp = GetTimeValue() - week*86400*7;
     SetTimeValue(tmp);
     return *this;
 }
Exemple #7
0
 CDateTime & CDateTime::DecSecond(UINT32 second)
 {
     time_t tmp = GetTimeValue() - second;
     SetTimeValue(tmp);
     return *this;
 }
Exemple #8
0
 CDateTime & CDateTime::DecMinute(UINT32 minute)
 {
     time_t tmp = GetTimeValue() - minute*60;
     SetTimeValue(tmp);
     return *this;
 }
Exemple #9
0
 CDateTime & CDateTime::DecHour(UINT32 hour)
 {
     time_t tmp = GetTimeValue() - hour*3600;
     SetTimeValue(tmp);
     return *this;
 }
Exemple #10
0
 CDateTime & CDateTime::DecDay(UINT32 day)
 {
     time_t tmp = GetTimeValue() - day*86400;
     SetTimeValue(tmp); 
     return *this;
 }