BYTE CTime::GetWeek(BYTE nFirstIsMonday) const
{
	struct tm Time;
	if (localtime_s(&Time,&m_time)!=0)
		return 0;
	return GetWeek(Time.tm_mday,Time.tm_mon,Time.tm_year+1900,nFirstIsMonday);
}
Example #2
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;
}
Example #3
0
CMyCalendar::CMyCalendar(int year,int month,int day)
{
	memset(&m_Time,0,sizeof(m_Time));
	m_Time.wDay=day;
	m_Time.wMonth=month;
	m_Time.wYear=year;
	m_Time.wDayOfWeek=GetWeek(year,month,day);
}
Example #4
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;
}
BYTE CTime::GetWeek(WORD nDay,WORD nMonth,WORD nYear,BYTE nFirstIsMonday)
{
	DWORD nFirstDate=GetIndex(1,1,nYear);
	DWORD nIndex=GetIndex(nDay,nMonth,nYear);
	BYTE nWeek=(BYTE)((nIndex-(nFirstDate-nFirstDate%7))/7)-((nIndex%7==0 && nFirstIsMonday!=0)?1:0);
	if((nFirstDate%7)<4)
		nWeek++;
	if (nWeek)
		return nWeek;
	nWeek=GetWeek(31,12,nYear-1,nFirstIsMonday);
	if (nWeek>53)
		return 1;
	return nWeek;
}
Example #6
0
void Key_Back() {
	uChar i;
	if (!isModify) {
		mainLoop = 0;
		for (i=0; i<ALARMNUM; i++) {
			if (isAlarm[i]) {			// 如果闹铃正在响则关闭
				isAlarm[i] = 0;
				if (1 == alarm[i][0])	// 如果闹铃为单一状态则设为关闭状态
					alarm[i][0] = 0;
			}
		}
		alarmNum = 0;
		beep = 1; 	// 按返回键关闭闹铃
		return;
	}
	if (0 == mainLoop) {	// 如果为设定时间
		isModify = 0;
		Set_RTC();
		return; 
	}
	if (1 == mainLoop) {	// 如果为设定日期
		isModify = 0;
		l_tmpdate[5] = GetWeek(l_tmpdate[6], l_tmpdate[4], l_tmpdate[3]);
							// 得到星期
		Set_RTC();
		return; 
	}	
	if (2 == mainLoop) {
		isModify = 0;
		return;
	}
	if (3 == mainLoop) {  // 如果为秒表
		if (isWatch) {
			sWatchFlag = 1;
			isWatch = 0;
			return;
		}
		isModify = 0;
		sWatchFlag = 0;
		return;
	}

	/********************继续添加功能***********************/
}
Example #7
0
int	CMyCalendar::InitalTime(SYSTEMTIME time)
{
	m_Time=time;
	m_Time.wDayOfWeek=GetWeek(m_Time.wYear,m_Time.wMonth,m_Time.wDay);
	return 1;
}