📄 time.cpp
字号:
#include "time.h"
static int dayInMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
GPSTIME::GPSTIME(GPSTIME& from)
{
this->iWeek = from.iWeek ;
this->ldSecond = from.ldSecond ;
}
bool GPSTIME::operator == (GPSTIME& temp)
{
if(this->iWeek == temp.iWeek && this->ldSecond == temp.ldSecond )
return true;
return false;
}
double GPSTIME::operator - (GPSTIME& temp)
{
GPSTIME result;
result.iWeek = this->iWeek - temp.iWeek ;
result.ldSecond = this->ldSecond - temp.ldSecond ;
return result.iWeek * 604800 + result.ldSecond ;
}
double GPSTIME::operator - (const GPSTIME& temp)
{
GPSTIME result;
result.iWeek = this->iWeek - temp.iWeek ;
result.ldSecond = this->ldSecond - temp.ldSecond ;
return result.iWeek * 604800 + result.ldSecond ;
}
ATIME::ATIME(const ATIME& from)
{
wYear = from.wYear;
byMonth = from.byMonth;
byDay = from.byDay;
byHour = from.byHour;
byMinute = from.byMinute;
bySecond = from.bySecond;
byDayOfWeek = from.byDayOfWeek;
}
void ATIME::ConvertToGpsTime(GPSTIME& GpsTime) //conver ATime to GPS TIME
{
int year,month,day,hour,minute;
long double second,weeksec;
year=this->wYear ;
month=this->byMonth ;
day=this->byDay ;
hour=this->byHour ;
minute=this->byMinute ;
second=this->bySecond ;
int dayofw,dayofy, yr, ttlday, m , weekno;
// Check limits of day, month and year
if (year < 1981 || month < 1 || month > 12 || day < 1 || day > 31)
weekno = 0;
// Convert day, month and year to day of year
if (month == 1)
dayofy = day;
else
{
dayofy = 0;
for (m=1; m<=(month-1); m++)
{
dayofy += dayInMonth[m];
if ( m==2 )
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
dayofy += 1;
}
}
dayofy += day;
}
// Convert day of year and year into week number and day of week
ttlday = 360; //GPS系统开始时间1980年1月6日(星期日)0时
for (yr=1981; yr<=(year-1); yr++)
{
ttlday += 365;
if ((yr % 4 == 0 && yr % 100 != 0) || (yr % 400 ==0))
ttlday += 1;
}
ttlday += dayofy;
weekno = ttlday/7;
dayofw = ttlday - 7 * weekno;
weeksec = (hour * 3600 + minute * 60 + second + dayofw * 86400);//从星期日起算
GpsTime.iWeek = weekno;
GpsTime.ldSecond = weeksec;
}
GPSTIME GPSTIME::operator -(const double dSec)
{
GPSTIME res;
double t;
int week;
t = this->ldSecond - dSec;
week = this->iWeek;
if(t<0)
{
t += 86400;
week -= 1;
}
res.iWeek = week;
res.ldSecond = t;
return res;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -