Example #1
0
ATL::CString GlobeFuns::TimeToFriendlyString(const CTime &t)
{
	CTimeSpan tmSpan = CTime::GetCurrentTime() - t;
	CString strRet;
	if (tmSpan.GetTotalMinutes()<1)
	{
		return "现在";
	}
	//if (tmSpan.GetTotalMinutes()<10)
	//{
	//	strRet.Format("%d分钟前",tmSpan.GetTotalMinutes());
	//	return strRet;
	//}
	if (tmSpan.GetTotalMinutes()<60)
	{
		strRet.Format("%d分钟前",tmSpan.GetTotalMinutes());
		return strRet;
	}
	if (tmSpan.GetTotalHours()<24)
	{
		strRet.Format("%d小时前",tmSpan.GetTotalHours());
		return strRet;
	}

	strRet.Format("%d天前",tmSpan.GetTotalHours()/24);
	return strRet;
}
Example #2
0
// 경과 시간 갱신
VOID CConsoleManager::UpdateElapsedTime( VOID )
{
	CTime CurrentTime = CTime::GetCurrentTime();
	LONGLONG dElapsedHour = 0;
	CTimeSpan ElapsedTime;

	// m_stOperationTime.StartTime와 CurrentTime 비교
	if( m_stOperationTime.StartTime > CurrentTime )
	{
		g_Log.WriteLog( false,
						LOG_CLASS_WARNING,
						TEXT( "%s | Operation time value is invalid.\n" ),
						TEXT( __FUNCTION__ ) );

		m_stOperationTime.wElapsedHour = 0;
		m_stOperationTime.wElapsedMinute = 0;
		return;
	}

	ElapsedTime = CurrentTime - m_stOperationTime.StartTime;

	// 경과 시 갱신
	dElapsedHour = ElapsedTime.GetTotalHours();
	if( 9999 < dElapsedHour )  // 365일 * 24시간 = 8760시간
		m_stOperationTime.wElapsedHour = 9999;
	else
		m_stOperationTime.wElapsedHour = static_cast<WORD>( dElapsedHour );

	// 경과 분 갱신
	m_stOperationTime.wElapsedMinute = static_cast<WORD>( ElapsedTime.GetMinutes() );
}
Example #3
0
//此函数暂时不使用
CString CMainFrame::GetRunningTime()
{
	CTimeSpan tSpan;
	tSpan = CTime::GetCurrentTime() - m_StartTime;
	LONGLONG totalSeconds = tSpan.GetTotalSeconds();
	LONGLONG totalMinutes = tSpan.GetTotalMinutes();
	LONGLONG totalHours = tSpan.GetTotalHours();
	CString strRet="";
	strRet.Format("%d天%02d时%02d分%02d秒",totalHours / 24,totalHours % 24,totalMinutes % 60,totalSeconds % 60);
	return strRet;
}
string VirtualListCtrlFT::FormatElapsed(CTimeSpan &span)
{
	string ret;
	char buf[4096];

	if(span.GetTotalHours()==0)	// < hour
	{
		sprintf(buf,"%u:%02u",span.GetMinutes(),span.GetSeconds());
	}
	else	//	> hour
	{
		sprintf(buf,"%u:%02u:%02u",span.GetHours(),span.GetMinutes(),span.GetSeconds());
	}
			
	ret=buf;

	return ret;
}
Example #5
0
void Alarm::CheckAndTrigger()
{
    if (ValidFieldFlags == 0)
        return;

    BOOL Triggered = TRUE;

    CTime now = CTime::GetCurrentTime();

    if ((ValidFieldFlags & VF_TIMEOFDAY) != 0)
    {
        if ((now.GetHour() != TimeOfDayHour) ||
                (now.GetMinute() != TimeOfDayMinute))
        {
            Triggered = FALSE;
        }
    }

    if ((ValidFieldFlags & VF_DAYOFWEEK) != 0)
    {
        if (now.GetDayOfWeek() != DayOfWeek)
            Triggered = FALSE;
    }

    if ((ValidFieldFlags & VF_DAYOFMONTH) != 0)
    {
        if (now.GetDay() != DayOfMonth)
            Triggered = FALSE;
    }

    if ((ValidFieldFlags & VF_MONTHOFYEAR) != 0)
    {
        if (now.GetMonth() != MonthOfYear)
            Triggered = FALSE;
    }

    if (Triggered)
    {
        CTimeSpan timeSinceLastTrigger = now - TimeLastTriggered;

        if ((ValidFieldFlags & VF_TIMEOFDAY) != 0)
        {
            if (timeSinceLastTrigger.GetTotalMinutes() < 2)
                Triggered = FALSE;
        }
        else if (((ValidFieldFlags & VF_DAYOFWEEK) != 0) ||
                 ((ValidFieldFlags & VF_DAYOFMONTH) != 0))
        {
            if (timeSinceLastTrigger.GetTotalHours() < 26)
                Triggered = FALSE;
        }
        else
        {
            if (timeSinceLastTrigger.GetTotalHours() < (24*33))
                Triggered = FALSE;
        }
    }

    if (Triggered)
    {
        TimeLastTriggered = now;

        TRACE1("TRIGGER: %s\n", TextMessage);

        DAlarmNotify& dlg = *new DAlarmNotify;
        dlg.TextMessage = TextMessage;
        dlg.Create(IDD_ALARMNOTIFY);
        dlg.ShowWindow(SW_SHOW);

        sndPlaySound(((CAlarmsDlg*)theApp.m_pMainWnd)->alarmsSoundFile,SND_ASYNC);
    }
}
Example #6
0
void CMirrorDlg::DispathNotification()
{
	NBSYNC_REPORT report;
	report.nSize = sizeof(NBSYNC_REPORT);
	CMultithreadedObserver::GerReport( static_cast<NDAS_SYNC_REPORT*>(&report) );

	if ( m_nCurrentPhase != report.nPhase )
	{
		m_nCurrentPhase = report.nPhase;
		switch( report.nPhase )
		{
		case NBSYNC_PHASE_CONNECT:
			m_strPhase = _T("Connecting to disks..."); // TODO : String resource
			DoDataExchange(FALSE);
			break;
		case NBSYNC_PHASE_REBIND:
			m_strPhase = _T("Updating disk information...");
			DoDataExchange(FALSE);
			break;
		case NBSYNC_PHASE_BIND:
			m_strPhase = _T("Writing disk information required for mirroring...");
			DoDataExchange(FALSE);
			break;
		case NBSYNC_PHASE_RETRIVE_BITMAP:
			m_strPhase = _T("Retrieving synchronization information..."); // TODO : String resource
			DoDataExchange(FALSE);
			break;
		case NBSYNC_PHASE_SYNCHRONIZE:
			m_strPhase = _T("Synchronizing..."); // TODO : String resource
			DoDataExchange(FALSE);
			break;
		case NBSYNC_PHASE_FINISHED:
			m_strPhase = _T("Synchronization has finished."); // TODO : String resource
			DoDataExchange(FALSE);
			m_bFinished = TRUE;
			break;
		case NBSYNC_PHASE_FAILED:
		default:
			if ( report.nErrorCode == NBSYNC_ERRORCODE_STOPPED )
			{
				m_strPhase = _T("Synchronization has been stopped.");
				DoDataExchange(FALSE);
			}
			else
			{
				m_strPhase = _T("Synchronization has failed.");
				DoDataExchange(FALSE);
			}
			break;
		}

		if ( report.bRebound && !m_bRebound )
		{
			boost::dynamic_pointer_cast<CDiskObjectComposite>
				(m_pDest->GetParent())->DeleteChild(m_pDest);
			if ( m_pMirDisks->front()->IsUsable() )
			{
				m_pMirDisks->DeleteChild( m_pMirDisks->back() );
			}
			else
			{
				m_pMirDisks->DeleteChild( m_pMirDisks->front() );
			}
			m_pMirDisks->AddChild(m_pMirDisks, m_pDest);
			m_bRebound = TRUE;
		}
	}

	// Display process
	if ( (m_nCurrentPhase == NBSYNC_PHASE_SYNCHRONIZE 
		  || m_nCurrentPhase == NBSYNC_PHASE_FINISHED
		  || m_nCurrentPhase == NBSYNC_PHASE_FAILED )
		&& report.nTotalSize != 0 )
	{
		// Step in progress bar
		UINT nNewStep = 
			static_cast<UINT>(
			   (report.nProcessedSize*m_progBar.GetRangeLimit(FALSE)) 
			 / report.nTotalSize
			);
		while ( m_progBar.GetPos() < nNewStep )
		{
			m_progBar.StepIt();
		}

		// Display progressbar message
		/*
		WTL::CString strProgBarMsg;

		strProgBarMsg.Format(
			"%d / %d KBs", 
			static_cast<int>(report.nProcessedSize/2),
			static_cast<int>(report.nTotalSize/2));
		m_progBar.SetWindowText( strProgBarMsg );
		*/

		// Display time left
		CTime timeNow = CTime::GetCurrentTime();
		CTimeSpan timeElapsed = timeNow - m_timeBegin;
		CTimeSpan timeLeft;
		if ( timeElapsed.GetTotalSeconds() != 0 
			&& m_timePrev != timeNow	// To prevent too frequent update
			)
		{
			m_timePrev = timeNow;
			// Calculate transfer rate
			double fMBPerSecond = 
				(report.nProcessedDirtySize) / 2.0 / 1024
				/ timeElapsed.GetTotalSeconds();
			

			WTL::CString strMBPerSecond;
			strMBPerSecond.Format( _T("%.01f"),fMBPerSecond);
			::SetWindowText( GetDlgItem(IDC_TEXT_RATE), strMBPerSecond );

			WTL::CString strTimeLeft;
			timeLeft = 
				static_cast<UINT>(
					(report.nTotalDirtySize-report.nProcessedDirtySize) 
					/ ( fMBPerSecond * 2 * 1024 )
				);
			int nHour, nMin, nSec;
			nSec = timeLeft.GetSeconds();
			nMin = timeLeft.GetMinutes();
			nHour = static_cast<int>(timeLeft.GetTotalHours());
			strTimeLeft.Format( _T("%02d:%02d:%02d"), nHour, nMin, nSec );
			//strTimeLeft = timeLeft.Format(TIME_FORMAT);
			::SetWindowText( GetDlgItem(IDC_TEXT_LEFTTIME), strTimeLeft );
		}
	}
	return;
}