Exemple #1
0
bool CMyTime::operator>(CMyTime& time)
{
	if(GetYear()>time.GetYear())return true;
	if(GetYear()==time.GetYear())
	{
		if(GetMonth()>time.GetMonth())return true;
		if(GetMonth()==time.GetMonth())
		{
			if(GetDay()>time.GetDay())return true;
			if(GetDay()==time.GetDay())
			{
				if(GetHour()>time.GetHour())return true;
				if(GetHour()==time.GetHour())
				{
					if(GetMinute()>time.GetMinute())return true;
					if(GetMinute()==time.GetMinute())
					{
						if(GetSecond()>time.GetSecond())return true;
					}
				}
			}
		}
	}
	return false;
}
DWORD CSPTime::ToStockTimeSecOrder( DWORD dwStockExchange )
{
	if( -1 == GetTime() || GetTime() < 0 || 0 == GetTime() )
		return 0;

	if( GetHour() < 9 || (GetHour() == 9 && GetMinute() < 30) )
		return 0;

	CSPTime tmStart = CSPTime(GetYear(),GetMonth(),GetDay(),9,30,0);
	CSPTime tmEnd	= CSPTime(GetYear(),GetMonth(),GetDay(),15,0,0);
	if( *this < tmStart )
		return 0;
	if( *this > tmEnd )
		return 14400;
	CSPTimeSpan	tmSpan	=	*this - tmStart;
	
	int	nSec	=	tmSpan.GetTotalSeconds();
	if( nSec >= 0 && nSec <= 7200 )
		return nSec;
	if( nSec > 7200 && nSec < 12600 )
		return 7200;
	if( nSec >= 12600 && nSec <= 19800 )
		return nSec-5400;

	ASSERT( FALSE );
	return 0;
}
Exemple #3
0
std::string CDateTime::GetLocalTime(std::string filter){
  std::string sOutput;
  std::ostringstream oss;

  if(filter == "MM/DD/YY"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetMonth() << "/" ;
    oss << std::setfill ('0') << std::setw(2);
    oss << GetDay() << "/";
    oss << std::setfill ('0') << std::setw(2);
    oss << (GetYear() - 2000);
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "MM-DD-YYYY"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetMonth() << "/" ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetDay() << "/" << GetYear();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "MM.DD.YYYY"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetMonth() << "." ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetDay() << "." << GetYear();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "HH:MM"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetHour() << ":" ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetMinute();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "HH:MM:SS"){
    oss << std::setfill ('0') << std::setw(2);
    oss << GetHour() << ":" ;
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetMinute() << ":";
    oss << std::setfill ('0') << std::setw(2);
    oss<< GetSecond();
    sOutput = oss.str();
    return sOutput;
  }
  else if(filter == "MONTH D, YYYY"){
    oss << GetMonthName() << " ";
    oss << GetDay() << ", " ;
    //oss << std::setfill ('0') << std::setw(2);
    oss<< GetYear();
    sOutput = oss.str();
    return sOutput;
  }

  return "";
}
Exemple #4
0
//This date class is designed to take on values which are considered invalid
//I want the date class to act not only as a date structure, but also
//as a way of finding differences of dates (not really fully implemented yet)
//So this function validates the date based on criteria for this specific project
//and guareentees that IsLeapYear() will work as it is expected to.
bool cTimeAndDate::IsValiDate() const { 

	bool ret=thisyear>1600;

	ret=ret && thismonth>=1 && thismonth<=12;
	ret=ret && GetDay().ofthemonth>=1 && GetDay().ofthemonth<=LengthOfMonth();
	return ret;
}
Exemple #5
0
int gettimeofday (struct timeval *tv, struct timezone *tz) {
    TTime tt;
    TDate td;

    GetDateTime(&td, &tt);

    if (NULL != tv) {
        struct tm t;
        t.tm_sec  = tt.sec;
        t.tm_min  = tt.min;
        t.tm_hour = tt.hour;
        t.tm_mday = td.day;
        t.tm_mon  = td.month-1;
        t.tm_year = td.year-1900;
        t.tm_wday = GetWeek(&td);
        t.tm_yday = GetDay(&td);
        t.tm_isdst = 0;
        t.tm_gmtoff = 10800;
        t.tm_zone = "EEST";

        tv->tv_sec = mktime(&t);
    }

    if (NULL != tz) {
        tz->tz_dsttime = 0;
        tz->tz_minuteswest = -180;
    }

    return 0;
}
Exemple #6
0
void XTime::GetTime(XString8 &strTime)
{
	int v=GetDayOfWeek();
	strTime=WeekDay(v);
	v=GetDay();
	if(v<10) strTime+=",0";
	else	 strTime+=",";
	strTime+=v;
	strTime+=' ';
	//v=GetMonth();
	strTime+=Month(GetMonth());
	strTime+=' ';
	strTime+=GetYear();
	strTime+=' ';
	if (this->GetHour()<10)
		strTime+='0';
	strTime+=GetHour();
	strTime+=':';
	if (this->GetMinute()<10)
		strTime+='0';
	strTime+=GetMinute();
	strTime+=':';
	if (this->GetSecond()<10)
		strTime+='0';
	strTime+=GetSecond();
	strTime+=" GMT";
}
Exemple #7
0
 bool HasEndDate(void) const
    {
       return GetDay() != m_EndDate.GetDay()
          || GetMonth() != m_EndDate.GetMonth()
          || GetYear() != m_EndDate.GetYear()
          ;
    }
UINT TimeManager::Time2DWORD( )
{
__ENTER_FUNCTION

	SetTime( ) ;

	UINT uRet=0 ;

	uRet += GetYear( ) ;
	uRet -= 2000 ;
	uRet =uRet*100 ;

	uRet += GetMonth( )+1 ;
	uRet =uRet*100 ;

	uRet += GetDay( ) ;
	uRet =uRet*100 ;

	uRet += GetHour( ) ;
	uRet =uRet*100 ;

	uRet += GetMinute( ) ;

	return uRet ;

__LEAVE_FUNCTION

	return 0 ;
}
Exemple #9
0
bool CMyCalendar::operator==(CMyCalendar& time)
{
	if(GetYear()==time.GetYear()&&
	   GetMonth()==time.GetMonth()&&
	   GetDay()==time.GetDay())
	   return true;
	return false;
}
Exemple #10
0
DWORD CSPTime::ToStockTimeDay( )
{
	if( -1 == GetTime() || GetTime() < 0 )
		return -1;
	if( 0 == GetTime() )
		return 0;

	return ( GetYear() * 10000 + GetMonth() * 100 + GetDay() );
}
Exemple #11
0
const Char_t *KVDatime::AsGanacqDateString() const
{
   //Return date and time string with format "29-SEP-2005 09:42:17.00"
   //Copy the string immediately if you want to reuse/keep it
   return Form("%d-%s-%4d %02d:%02d:%02d.00",
               GetDay(),
               ((TObjString *) fmonths->At(GetMonth() - 1))->String().
               Data(), GetYear(), GetHour(), GetMinute(), GetSecond());
}
void CXTPDatePickerItemMonth::ByFontAdjustLayout(CRect rcClient)
{
	CWindowDC dc(CWnd::GetDesktopWindow());
	CSize szDay(m_pControl->m_pPaintManager->CalcDayRect(&dc));
	CSize szHeader(m_pControl->m_pPaintManager->CalcMonthHeaderRect(&dc));
	CSize szWeekText(m_pControl->m_pPaintManager->CalcDayOfWeekRect(&dc));
	CSize szWeekNumber(m_pControl->m_pPaintManager->CalcWeekNumbersRect(&dc));

	m_rcMonth = rcClient;
	// calc header rect
	m_rcHeader = m_rcMonth;
	m_rcHeader.bottom = m_rcHeader.top + szHeader.cy;
	//m_rcHeader.right = m_rcHeader.left + szHeader.cx;

	// calc days of week rect
	m_rcDaysOfWeek = m_rcMonth;
	m_rcDaysOfWeek.top = m_rcHeader.bottom;
	//m_rcDaysOfWeek.bottom = m_rcDaysOfWeek.top + 18; // TODO: change to font height
	m_rcDaysOfWeek.bottom = m_rcDaysOfWeek.top + szWeekText.cy;

	// draw week numbers
	m_rcWeekNumbers = m_rcMonth;
	m_rcWeekNumbers.top = m_rcDaysOfWeek.bottom;
	//m_rcWeekNumbers.right = m_rcWeekNumbers.left + 18; // TODO: change to font width
	m_rcWeekNumbers.right = m_rcWeekNumbers.left + szWeekNumber.cx;

	// calc triangles rect
	m_rcLeftScroll = m_rcHeader;
	m_rcRightScroll = m_rcHeader;
	m_rcLeftScroll.right = m_rcHeader.left+ szWeekNumber.cx + 3;
	m_rcRightScroll.left = m_rcHeader.right - szWeekNumber.cx - 3;

	// calc days display params
	m_rcDaysArea = m_rcMonth;
	m_rcDaysArea.top = m_rcDaysOfWeek.bottom;
	m_rcDaysArea.left = m_rcWeekNumbers.right;
	m_rcDaysArea.right -= m_rcWeekNumbers.Width();

	CRect rcDay;
	int nIndex = 0;
	for (int nWeek = 0; nWeek < XTP_MAX_WEEKS; nWeek++)
	{
		for (int nDay = 0; nDay < XTP_WEEK_DAYS; nDay++)
		{
			CXTPDatePickerItemDay* pDay = GetDay(nIndex);
			nIndex++;

			rcDay.left = m_rcDaysArea.left + nDay * szDay.cx + 1;
			rcDay.top = m_rcDaysArea.top + nWeek * szDay.cy;
			rcDay.right = rcDay.left + szDay.cx ;
			rcDay.bottom = rcDay.top + szDay.cy;
			pDay->SetRect(rcDay);
		}
	}

}
Exemple #13
0
CMyCalendar& CMyCalendar::operator-=(CMyTimeInterval& timeInterval)
{
	if(!timeInterval.GetSingal())
	{
		CMyTimeInterval t=timeInterval;
		t.SetSingal(true);
		return *this+=t;
	}
	int days=timeInterval.GetDays();
	if(days<=0)return *this;
	int y=GetYear();
	int m=GetMonth();
	int d=GetDay();
	int less=YearDaysLess(y,m,d);
	int uless=YearDays(y)-less;
	if(days<uless)
	{
		//没有跨年
		if(days<d)
		{
			//没有跨月
			m_Time.wDay-=days;
		}
		else
		{
			//跨月
			days-=d;
			int md=0;
			while(1)
			{
				md=MonthDays(y,--m);
				if(md>=days)break;
				days-=md;
			}
			m_Time.wDay=md-days;
			m_Time.wMonth=m;
		}
	}
	else
	{
		//跨年
		days-=uless;
		int yd=0;
		while(1)
		{
			yd=YearDays(--y);
			if(yd>=days)break;
			days-=yd;
		}
		m_Time.wMonth=MonthDayInYear(y,YearDays(y)-days,(int &)m_Time.wDay);
		m_Time.wYear=y;
	}

	m_Time.wDayOfWeek=GetWeek(m_Time.wYear,m_Time.wMonth,m_Time.wDay);
	return *this;
}
Exemple #14
0
DWORD CSPTime::ToStockTimeMin( )
{
	if( -1 == GetTime() || GetTime() < 0 )
		return -1;
	if( 0 == GetTime() )
		return 0;

	return ( (GetYear() - 1990) * 100000000 + GetMonth() * 1000000 + GetDay() * 10000
			+ GetHour() * 100 + GetMinute() );
}
void UKismetMathLibrary::BreakDateTime(FDateTime InDateTime, int32& Year, int32& Month, int32& Day, int32& Hour, int32& Minute, int32& Second, int32& Millisecond)
{
	Year = GetYear(InDateTime);
	Month = GetMonth(InDateTime);
	Day = GetDay(InDateTime);
	Hour = GetHour(InDateTime);
	Minute = GetMinute(InDateTime);
	Second = GetSecond(InDateTime);
	Millisecond = GetMillisecond(InDateTime);
}
void CDxDatePickerMonth::AutoAdjustLayout(CRect rcClient)
{
    m_rcMonth = rcClient;
    // calc header rect
    m_rcHeader = m_rcMonth;
    m_rcHeader.left  += 2;
    m_rcHeader.right -= 2;
    m_rcHeader.bottom = m_rcHeader.top + 18; // TODO: change to font height

    // calc days of week rect
    m_rcDaysOfWeek = m_rcMonth;
    m_rcDaysOfWeek.top = m_rcHeader.bottom;
    m_rcDaysOfWeek.bottom = m_rcDaysOfWeek.top + 18; // TODO: change to font height

    // draw week numbers
    m_rcWeekNumbers = m_rcMonth;
    m_rcWeekNumbers.top = m_rcDaysOfWeek.bottom;
    m_rcWeekNumbers.right = m_rcWeekNumbers.left + 18; // TODO: change to font width

    // calc triangles rect
    m_rcLeftScroll = m_rcHeader;
    m_rcRightScroll = m_rcHeader;
    int nScrollWidth = min(m_rcWeekNumbers.Width(), m_rcHeader.Width() / 8);
    m_rcHeader.left += nScrollWidth;
    m_rcHeader.right -= nScrollWidth;
    m_rcLeftScroll.right = m_rcHeader.left;
    m_rcRightScroll.left = m_rcHeader.right;

    // calc days display params
    m_rcDaysArea = m_rcMonth;
    m_rcDaysArea.top = m_rcDaysOfWeek.bottom;
    m_rcDaysArea.left = m_rcWeekNumbers.right;
    m_rcDaysArea.right -= m_rcWeekNumbers.Width();

    // calc simple day rect sizes
    CSize szDay(m_rcDaysArea.Width() / XTP_WEEK_DAYS, m_rcDaysArea.Height() / XTP_MAX_WEEKS);

    // calc rects for all days
    CRect rcDay;
    int nIndex = 0;
    for (int nWeek = 0; nWeek < XTP_MAX_WEEKS; nWeek++)
    {
        for (int nDay = 0; nDay < XTP_WEEK_DAYS; nDay++)
        {
            CDxDatePickerDay* pDay = GetDay(nIndex);
            nIndex++;

            rcDay.left = m_rcDaysArea.left + nDay * szDay.cx + 1;
            rcDay.top = m_rcDaysArea.top + nWeek * szDay.cy;
            rcDay.right = rcDay.left + szDay.cx;
            rcDay.bottom = rcDay.top + szDay.cy;
            pDay->SetRect(rcDay);
        }
    }
}
void CXTPDatePickerItemMonth::ClearDays()
{
	// cleanup old month array
	int nOldDayCount = GetDayCount();
	for (int nDay = 0; nDay < nOldDayCount; nDay++)
	{
		CXTPDatePickerItemDay* pDay = GetDay(nDay);
		pDay->InternalRelease();
	}
	m_arrDays.RemoveAll();
}
void CDxDatePickerMonth::ClearDays()
{
    // cleanup old month array
    int nOldDayCount = GetDayCount();
    for (int nDay = 0; nDay < nOldDayCount; nDay++)
    {
        CDxDatePickerDay* pDay = GetDay(nDay);
        delete pDay;
    }
    m_arrDays.RemoveAll();
}
Exemple #19
0
CTime CDate_std::AsCTime(CTime::ETimeZone tz) const
{
    return CTime(GetYear(),
                 CanGetMonth()  ? GetMonth()  : 1,
                 CanGetDay()    ? GetDay()    : 1,
                 CanGetHour()   ? GetHour()   : 0,
                 CanGetMinute() ? GetMinute() : 0,
                 CanGetSecond() ? GetSecond() : 0,
                 0, // nanoseconds, not supported by CDate_std.
                 tz);
}
Exemple #20
0
bool CMyCalendar::operator>(CMyCalendar& time)
{
	if(GetYear()>time.GetYear())return true;
	if(GetYear()==time.GetYear())
	{
		if(GetMonth()>time.GetMonth())return true;
		if(GetMonth()==time.GetMonth())
		{
			if(GetDay()>time.GetDay())return true;
		}
	}
	return false;
}
CDxDatePickerDay* CDxDatePickerMonth::HitTest(CPoint point, BOOL bCheckVisible) const
{
    // enumerate month array
    int nDayCount = GetDayCount();
    for (int nDay = 0; nDay < nDayCount; nDay++)
    {
        CDxDatePickerDay* pDay = GetDay(nDay);
        if (pDay && pDay->GetRect().PtInRect(point) && (pDay->IsVisible() || !bCheckVisible))
        {
            return pDay;
        }
    }
    return NULL;
}
Exemple #22
0
void DWordToDate(DWORD dwDate,LPSTR szBuffer)
{
	if (dwDate==0)
	{
		szBuffer[0]=0;
	}
	else
	{
		WORD wYear=GetYear(dwDate);
		WORD wMonth=GetMonth(dwDate);
		WORD wDay=GetDay(dwDate);
		sprintf(szBuffer,"%.4i,%.2i,%.2i",(int)wYear,(int)wMonth,(int)wDay);
	}
}
Exemple #23
0
tuint32 TimeManager::Time2Day()
{
	tuint32 uRet = 0;

	uRet += GetYear();
	uRet *= 100;

	uRet += GetMonth() + 1;
	uRet *= 100;

	uRet += GetDay();

	return uRet;
}
void CDxDatePickerMonth::Draw(CDCHandle dc)
{
    // draw header
    DrawMonthHeader(dc);

    // draw days of week
    DrawDaysOfWeek(dc);

    //  draw all days
    int nDaysCount = GetDayCount();
    for (int nIndex = 0; nIndex < nDaysCount; nIndex++)
    {
        CDxDatePickerDay* pDay = GetDay(nIndex);
        pDay->Draw(dc);
    }
}
int CountSundaysOnFirstOfMonth()
{
	int yearStart = 1901;
	int yearEnd = 2000;
	int nrSundays = 0;

	for (int yyyy = yearStart; yyyy <= yearEnd; ++yyyy)
	{
		for (int mm = 1; mm <= 12; ++mm)
		{
			if (GetDay(1, mm, yyyy) == 0)
			{
				++nrSundays;
			}
		}
	}
	return nrSundays;
}
Exemple #26
0
int main(int argc, char *argv[])
{
	int day;
	for(int i=0;i<21;i++)
	{
		scanf("%d",&day);

		if(day==0)
			break;

		int n1,l1;
		GetDay(n1,l1,day);

		printf("%d %d\n",day,n1*(n1+1)*(2*n1+1)/6+l1*(n1+1));
	}
	
	return 0;
}
void HttpServerLog::GetTimestamp(const std::time_t& time, int& year, int& month, int& day, int& hour, int& min, int& sec) {
    auto totalDays = time / 86400;
    auto elapsedYears = (long)(totalDays / 365.25);
    auto leapYears = ((long)elapsedYears) / 4;
    auto yearStart = ((elapsedYears - leapYears) * 31536000) + (leapYears * 31622400);
    auto elapsedSecondsThisYear = time - yearStart;    
    
    year = 1970 + elapsedYears;
    auto isLeap = (year % 4) == 0;
    month = GetMonth(elapsedSecondsThisYear, isLeap);
    day = GetDay(elapsedSecondsThisYear, month, isLeap);
        
    ++month;
    ++day;
    
    hour = (time % (24 * 60 * 60)) / (60 * 60);
    min = (time % (60 * 60)) / 60;
    sec = time % 60;
}
Exemple #28
0
inline string _date_::ToStdString() const {
	string convertita = "";
	ostringstream out;
	out.fill('0');
	out.width(2);
	out << GetYear();
	out.width(1);
	out	<< '-';
	out.fill('0');
	out.width(2);
	out	<< GetMonth();
	out.width(1);
	out	<< '-';
	out.fill('0');
	out.width(2);
	out	<< GetDay();
	convertita = out.str();
	return convertita;
}
Exemple #29
0
// negative values mean day/month/year/hour/minute is in the past
int	MinutesBefore(int day, int month, int year, int hour, int minute) {
	int	td=GetDay(),
		tm=GetMonth(),
		ty=GetYear(),
		th=GetHour(),
		tmin=GetMinute();
		
	int32	m1, m2;
	
	m1=(int32)GetDaysFrom1984To(td, tm, ty)*24*60;
	m1+=th*60+tmin;
	// m1: minutes since 01/01/1984 (until now).
	
	m2=(int32)GetDaysFrom1984To(day, month, year)*24*60;
	m2+=hour*60+minute;
	// m2: minutes since 01/01/1984 until month/day/year.
	
	return m2-m1;	
}
Exemple #30
0
//例如:20070403表示2007年4月3日
UINT TimeManager::Time2Day( )
{
	__ENTER_FUNCTION

		UINT uRet=0 ;

	uRet += GetYear( ) ;

	uRet =uRet*100 ;
	uRet += GetMonth( )+1 ;

	uRet =uRet*100 ;
	uRet += GetDay( ) ;

	return uRet ;

	__LEAVE_FUNCTION

		return 0 ;
}