コード例 #1
0
/**
 *	Generates a display string showing the relative time between the two given times as COleDateTimes
 */
CString CLoglistUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo)
{
	COleDateTimeSpan ts = RelativeTo - time;

	//years
	if(fabs(ts.GetTotalDays()) >= 3 * 365)
		return ExpandRelativeTime((int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO);

	//Months
	if(fabs(ts.GetTotalDays()) >= 60)
		return ExpandRelativeTime((int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO);

	//Weeks
	if(fabs(ts.GetTotalDays()) >= 14)
		return ExpandRelativeTime((int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO);

	//Days
	if(fabs(ts.GetTotalDays()) >= 2)
		return ExpandRelativeTime((int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO);

	//hours
	if(fabs(ts.GetTotalHours()) >= 2)
		return ExpandRelativeTime((int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO);

	//minutes
	if(fabs(ts.GetTotalMinutes()) >= 2)
		return ExpandRelativeTime((int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO);

	//seconds
	return ExpandRelativeTime((int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO);
}
コード例 #2
0
ファイル: ActiveMember.cpp プロジェクト: layerfsd/PersonalIBA
CString CActiveMember::GetUseTimeAsString()
{
	CString strTmp;

	if ( GetIsOnLine() )
	{
		COleDateTime dtNow = COleDateTime::GetCurrentTime();

		COleDateTimeSpan dts = dtNow - CheckInTime;

		//系统时间跟中心事件有差错时,可能存在为负的情况
		if (dts < COleDateTimeSpan(0, 0, 0, 0))//时间为负
		{
			strTmp.Format(_T("%.2d:%.2d"), 0, 0);
		}
		else//正常
		{
			//{ 2011/04/22-gxx: 修改原来支持最大时长24小时为总时长, GetHours()-->GetTotalHours()
			int nHours = (int)dts.GetTotalHours();
			strTmp.Format(_T("%.2d:%.2d"), nHours, dts.GetMinutes());
			//}		
		}
	}

	return strTmp;
}
コード例 #3
0
void CDefineBundleTimeDlg::OnEndTimeChanged()
{
	COleDateTime startTime;
	startTime.ParseDateTime(m_btnStartTime.ToString());

	COleDateTime endTime;
	endTime.ParseDateTime(m_btnEndTime.ToString());

	if (endTime <= startTime)
	{
		m_btnEndTime.SetDate(startTime);
		endTime.ParseDateTime(m_btnEndTime.ToString());
	}

	COleDateTimeSpan sp = endTime - startTime;

	INT nHours = (long)sp.GetTotalHours();
	INT nMinutes = sp.GetMinutes();

	CString strTmp;
	strTmp.Format(_T("%d"), nHours);
	m_edtHours.SetWindowText(strTmp);

	strTmp.Format(_T("%d"), nMinutes);
	m_edtMinutes.SetWindowText(strTmp);

	TRACE("OnEndTimeChanged\n");
}
コード例 #4
0
ファイル: ComputerInfo.cpp プロジェクト: layerfsd/PersonalIBA
CString CComputerInfo::GetUseTimeAsString()
{
	CString strTmp;

	// 2011/07/11-8201-gxx: 
	if (m_CheckInTime.GetStatus() == COleDateTime::invalid ||
		m_CheckInTime.GetStatus() == COleDateTime::null)
	{
		return strTmp;
	}

	if (m_bHasUserInfo || ECS_UNLOCK == m_ComputerStatus)
	{
		COleDateTime dtNow = COleDateTime::GetCurrentTime();
		
		COleDateTimeSpan dts = dtNow - m_CheckInTime;

		//系统时间跟中心事件有差错时,可能存在为负的情况
		if (dts < COleDateTimeSpan(0, 0, 0, 0))//时间为负
		{
			strTmp.Format(_T("%.2d:%.2d"), 0, 0);
		}
		else if( m_CheckInTime == 0 ) // 上机时间为0,表示没有上机
		{
			strTmp = _T("");
			return strTmp;
		}
		else//正常
		{
			//{ 2011/04/22-gxx: 修改原来支持最大时长24小时为总时长, GetHours()-->GetTotalHours()
			int nHours = (int)dts.GetTotalHours();
			strTmp.Format(_T("%.2d:%.2d"), nHours, dts.GetMinutes());
			//}			
		}
	}

	return strTmp;
}
コード例 #5
0
ファイル: ChartAxis.cpp プロジェクト: fara-ramin/firewall
void CChartAxis::CalculateTickIncrement()
{
	if (!m_bAutoTicks)
		return;

	if (m_MaxValue == m_MinValue)
	{
		m_iDTTickIntervalMult = 0;
		m_TickIncrement = 0;
		return;
	}

	int PixelSpace;
	if (m_bIsHorizontal)
	{
		if (m_AxisType == atDateTime)
			PixelSpace = 60;
		else
			PixelSpace = 30;
	}
	else
		PixelSpace = 20;

	int MaxTickNumber = (int)fabs((m_EndPos-m_StartPos)/PixelSpace * 1.0);

	//Calculate the appropriate TickSpace (1 tick every 30 pixel +/-)
	switch (m_AxisType)
	{
	case atLogarithmic:
	   m_TickIncrement = 10;
	   break;

	case atStandard:
		{
	   		//Temporary tick increment
    		double TickIncrement = (m_MaxValue-m_MinValue)/MaxTickNumber;
	    
    		// Calculate appropriate tickSpace (not rounded on 'strange values' but 
    		// on something like 1, 2 or 5*10^X  where X is optimalized for showing the most
    		// significant digits)
    		int Zeros = (int)floor(log10(TickIncrement));
    		double MinTickIncrement = pow(10.0,Zeros);
	    
    		int Digits = 0;
    		if (Zeros<0)		
    		{
				//We must set decimal places. In the other cases, Digits will be 0.
    			Digits = (int)fabs(Zeros*1.0);
    		}
	    
    		if (MinTickIncrement>=TickIncrement)
    		{
    			m_TickIncrement = MinTickIncrement;
    			SetDecimals(Digits);
    		}
    		else if (MinTickIncrement*2>=TickIncrement)
    		{
    			m_TickIncrement = MinTickIncrement*2;
    			SetDecimals(Digits);
    		}
    		else if (MinTickIncrement*5>=TickIncrement)
    		{
    			m_TickIncrement = MinTickIncrement*5;
    			SetDecimals(Digits);
    		}
    		else if (MinTickIncrement*10>=TickIncrement)
    		{
    			m_TickIncrement = MinTickIncrement*10;
    			if (Digits)
    				SetDecimals(Digits-1);
    			else
    				SetDecimals(Digits);
    		}
		}
		break;

	case atDateTime:
		{
			COleDateTime StartDate(m_MinValue);
			COleDateTime EndDate(m_MaxValue);

			COleDateTimeSpan minTickInterval = (EndDate - StartDate)/MaxTickNumber;
			double Seconds = minTickInterval.GetTotalSeconds();
			double Minutes = minTickInterval.GetTotalMinutes();
			double Hours = minTickInterval.GetTotalHours();
			double Days = minTickInterval.GetTotalDays();
			if (Seconds < 60)
			{
				m_BaseInterval = tiSecond;
				if (Seconds > 30)
				{
					m_BaseInterval = tiMinute;
					m_iDTTickIntervalMult = 1;
				}
				else if (Seconds > 10)
					m_iDTTickIntervalMult = 30;
				else if (Seconds > 5)
					m_iDTTickIntervalMult = 10;
				else if (Seconds > 2)
					m_iDTTickIntervalMult = 5;
				else 
					m_iDTTickIntervalMult = 1;
			}
			else if (Minutes < 60)
			{
				m_BaseInterval = tiMinute;
				if (Minutes > 30)
				{
					m_BaseInterval = tiHour;
					m_iDTTickIntervalMult = 1;
				}
				else if (Minutes > 10)
					m_iDTTickIntervalMult = 30;
				else if (Minutes > 5)
					m_iDTTickIntervalMult = 10;
				else if (Minutes > 2)
					m_iDTTickIntervalMult = 5;
				else 
					m_iDTTickIntervalMult = 2;
			}
			else if (Hours < 24)
			{
				m_BaseInterval = tiHour;
				if (Hours > 12)
				{
					m_BaseInterval = tiDay;
					m_iDTTickIntervalMult = 1;
				}
				else if (Hours > 6)
					m_iDTTickIntervalMult = 12;
				else if (Hours > 2)
					m_iDTTickIntervalMult = 6;
				else 
					m_iDTTickIntervalMult = 2;
			}
			else if (Days < 31)
			{
				m_BaseInterval = tiDay;
				if (Days > 7)
				{
					m_BaseInterval = tiMonth;
					m_iDTTickIntervalMult = 1;
				}
				else if (Days > 2)
				{
					m_BaseInterval = tiDay;
					m_iDTTickIntervalMult = 7;
				}
				else 
					m_iDTTickIntervalMult = 2;
			}
			else if (Days < 365)
			{
				m_BaseInterval = tiMonth;
				if (Days > 186)	 // Approx 6 months
				{
					m_BaseInterval = tiYear;
					m_iDTTickIntervalMult = 1;
				}
				else if (Days > 124)
					m_iDTTickIntervalMult = 6;
				else if (Days > 62)
					m_iDTTickIntervalMult = 4;
				else
					m_iDTTickIntervalMult = 2;
			}
			else
			{
				m_BaseInterval = tiYear;
				m_iDTTickIntervalMult = (int)Days/365 + 1;
			}

			if (m_bAutoTickFormat)
				RefreshDTTickFormat();
		}
		break;
	}
}
コード例 #6
0
void CDlgBundleTimeList::OnOK()
{
	INT nIndex = m_BundleTimeList.GetSelectionMark();

	if (nIndex >= 0)
	{	
		//取得绑定数据
		INT nBtIndex = m_BundleTimeList.GetItemData(nIndex);
		
		m_nBundleTimeId = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeId();

		m_nBundleTimeClassId = NetbarBundleTime.GetAt(nBtIndex).IsNowEnabled() ? 0 : 1;

		//开始时间
		m_strStartTime = NetbarBundleTime.GetAt(nBtIndex).GetStartTime(TRUE).Left(5);
		//结束时间
		m_strEndTime = NetbarBundleTime.GetAt(nBtIndex).GetEndTime(TRUE).Left(5);
		//包时扣费类型
		m_nBundleTimeType = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeType();

		COleDateTimeSpan RemainTime;

		if (NetbarBundleTime.GetAt(nBtIndex).GetStartTime().IsEmpty())
		{
			RemainTime = COleDateTimeSpan(0, NetbarBundleTime.GetAt(nBtIndex).GetTimePass(), 0, 0);
		}
		else
		{
			COleDateTime StartTime, EndTime, CurTime = COleDateTime::GetCurrentTime();
			
			StartTime.ParseDateTime(NetbarBundleTime.GetAt(nBtIndex).GetStartTime(TRUE));
			StartTime.SetDateTime(CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(),
				StartTime.GetHour(), StartTime.GetMinute(), StartTime.GetSecond());

			EndTime.ParseDateTime(NetbarBundleTime.GetAt(nBtIndex).GetEndTime(TRUE));
			EndTime.SetDateTime(CurTime.GetYear(), CurTime.GetMonth(), CurTime.GetDay(),
				EndTime.GetHour(), EndTime.GetMinute(), EndTime.GetSecond());

			if (StartTime > EndTime) //跨天包时
			{
				if (CurTime < EndTime)
				{
					StartTime -= COleDateTimeSpan(1, 0, 0, 0); //减去一天
				}
				else
				{
					EndTime += COleDateTimeSpan(1, 0, 0, 0); //加上一天
				}
			}
			
			if (CurTime < StartTime) //包时还没开始
			{
				RemainTime = COleDateTimeSpan(0, NetbarBundleTime.GetAt(nBtIndex).GetTimePass(), 0, 0);
			}
			else if (CurTime > EndTime) //包时已经过期,只能开始算明天的包时
			{

			}
			else //包时正在进行
			{
				RemainTime = EndTime - CurTime;
			}

			//AfxMessageBox(StartTime.Format(_T("%Y-%m-%d %H:%M:%S")));
			//AfxMessageBox(EndTime.Format(_T("%Y-%m-%d %H:%M:%S")));
			//AfxMessageBox(m_strRemainTime);
		} 
		
		//m_strRemainTime = RemainTime.Format(_T("%H:%M:%S"));

		m_strRemainTime.Format(_T("%02d:%02d:%02d"), 
			(long)RemainTime.GetTotalHours(), RemainTime.GetMinutes(), RemainTime.GetSeconds());

		//包时金额
		m_nBundleTimeMoney = NetbarBundleTime.GetAt(nBtIndex).GetBundleTimeMoney();

		CBCGPDialog::OnOK();
	}
}
コード例 #7
0
double CChartDateTimeAxis::GetTickBeforeVal(double dValue) const
{
	double precision = 0.0000000001;
	if (dValue < 0)
		precision = -0.0000000001;

	COleDateTime tickBefore;
	COleDateTime valueTime = COleDateTime(DATE(dValue+precision));
	COleDateTimeSpan dtSpan = valueTime - m_ReferenceTick;
	switch (m_BaseInterval)
	{
	case tiSecond:
		{
			int totalSecs = (int)dtSpan.GetTotalSeconds();
			totalSecs = (totalSecs/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			int Days = totalSecs/86400;					// 86400 seconds in one day
			int Hours = (totalSecs%86400)/3600;			// 3600 seconds in one hour
			int Minutes = ((totalSecs%86400)%3600)/60;	// 60 seconds in one minute
			int Seconds = ((totalSecs%86400)%3600)%60;
			dtSpan.SetDateTimeSpan(Days, Hours, Minutes, Seconds);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiMinute:
		{
			int totalMinutes = (int)dtSpan.GetTotalMinutes();
			totalMinutes = (totalMinutes/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			int Days = totalMinutes/1440;			// 1440 minutes in one day
			int Hours = (totalMinutes%1440)/60;		// 60 minutes in one hour
			int Minutes = (totalMinutes%1440)%60;
			dtSpan.SetDateTimeSpan(Days, Hours, Minutes, 0);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiHour:
		{
			int totalHours = (int)dtSpan.GetTotalHours();
			totalHours = (totalHours/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			int Days = totalHours/24;			// 24 hours in one day
			int Hours = totalHours%24;
			dtSpan.SetDateTimeSpan(Days, Hours, 0, 0);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiDay:
		{
			int totalDays = (int)dtSpan.GetTotalDays();
			totalDays = (totalDays/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			dtSpan.SetDateTimeSpan(totalDays, 0, 0, 0);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiMonth:
		{
			int yearDiff = valueTime.GetYear() - m_ReferenceTick.GetYear();
			int monthDiff = valueTime.GetMonth() - m_ReferenceTick.GetMonth();
			int totalMonths = ((yearDiff*12+monthDiff)/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			tickBefore = AddMonthToDate(m_ReferenceTick,totalMonths);
		}
		break;
	case tiYear:
		{
			int yearDiff = valueTime.GetYear() - m_ReferenceTick.GetYear();
			int year = ((yearDiff)/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			tickBefore = AddMonthToDate(m_ReferenceTick,year*12);
		}
		break;
	}

	return (DATE)tickBefore;
}
コード例 #8
0
void CChartDateTimeAxis::RefreshTickIncrement()
{
	if (!m_bAutoTicks)
		return;

	if (m_MaxValue == m_MinValue)
	{
		m_iDTTickIntervalMult = 1;
		return;
	}

	int PixelSpace;
	if (m_bIsHorizontal)
		PixelSpace = 60;
	else
		PixelSpace = 20;

	int MaxTickNumber = (int)fabs((m_EndPos-m_StartPos)/PixelSpace * 1.0);
	if (MaxTickNumber == 0)
		MaxTickNumber = 1;

	COleDateTime StartDate(m_MinValue);
	COleDateTime EndDate(m_MaxValue);

	COleDateTimeSpan minTickInterval = (EndDate - StartDate)/MaxTickNumber;
	double Seconds = minTickInterval.GetTotalSeconds();
	double Minutes = minTickInterval.GetTotalMinutes();
	double Hours = minTickInterval.GetTotalHours();
	double Days = minTickInterval.GetTotalDays();
	if (Seconds < 60)
	{
		m_BaseInterval = tiSecond;
		if (Seconds > 30)
		{
			m_BaseInterval = tiMinute;
			m_iDTTickIntervalMult = 1;
		}
		else if (Seconds > 10)
			m_iDTTickIntervalMult = 30;
		else if (Seconds > 5)
			m_iDTTickIntervalMult = 10;
		else if (Seconds > 2)
			m_iDTTickIntervalMult = 5;
		else
			m_iDTTickIntervalMult = 1;
	}
	else if (Minutes < 60)
	{
		m_BaseInterval = tiMinute;
		if (Minutes > 30)
		{
			m_BaseInterval = tiHour;
			m_iDTTickIntervalMult = 1;
		}
		else if (Minutes > 10)
			m_iDTTickIntervalMult = 30;
		else if (Minutes > 5)
			m_iDTTickIntervalMult = 10;
		else if (Minutes > 2)
			m_iDTTickIntervalMult = 5;
		else
			m_iDTTickIntervalMult = 2;
	}
	else if (Hours < 24)
	{
		m_BaseInterval = tiHour;
		if (Hours > 12)
		{
			m_BaseInterval = tiDay;
			m_iDTTickIntervalMult = 1;
		}
		else if (Hours > 6)
			m_iDTTickIntervalMult = 12;
		else if (Hours > 2)
			m_iDTTickIntervalMult = 6;
		else
			m_iDTTickIntervalMult = 2;
	}
	else if (Days < 31)
	{
		m_BaseInterval = tiDay;
		if (Days > 7)
		{
			m_BaseInterval = tiMonth;
			m_iDTTickIntervalMult = 1;
		}
		else if (Days > 2)
		{
			m_BaseInterval = tiDay;
			m_iDTTickIntervalMult = 7;
		}
		else
			m_iDTTickIntervalMult = 2;
	}
	else if (Days < 365)
	{
		m_BaseInterval = tiMonth;
		if (Days > 186)	 // Approx 6 months
		{
			m_BaseInterval = tiYear;
			m_iDTTickIntervalMult = 1;
		}
		else if (Days > 124)
			m_iDTTickIntervalMult = 6;
		else if (Days > 62)
			m_iDTTickIntervalMult = 4;
		else
			m_iDTTickIntervalMult = 2;
	}
	else
	{
		m_BaseInterval = tiYear;
		m_iDTTickIntervalMult = (int)Days/365 + 1;
	}
}