📄 otime.cpp
字号:
while( lsecond < 0 )
{
lday -- ;
lsecond += SECOND_OF_DAY;
}
otimespan.Set( lday , lsecond ) ;
return otimespan ;
}
*/
/********************************************************************
Return Value:otimespan instance
Parameters: OTime instance to be added
********************************************************************/
OTime& OTime::operator +=( OTimeSpan otimespan)
{
long total_day,total_second;
total_day = AbsDay( ) + otimespan.GetDay( );
total_second = AbsSecond() + otimespan.GetSecondinDay( );
total_day += total_second / SECOND_OF_DAY;
total_second = total_second % SECOND_OF_DAY;
AbsToDate( total_day );
AbsToTime( total_second );
return *this;
}
/********************************************************************
Return Value:otimespan instance
Parameters: OTime instance to be minus
********************************************************************/
OTime& OTime::operator -=( OTimeSpan otimespan)
{
long total_day,total_second;
total_day = AbsDay( ) - otimespan.GetDay( );
total_second = AbsSecond() - otimespan.GetSecondinDay( );
while( total_second < 0 )
{
total_day -- ;
total_second += SECOND_OF_DAY ;
}
AbsToDate( total_day );
AbsToTime( total_second );
return *this;
}
/********************************************************************
Return Value:compare result
Parameters: OTime instance
********************************************************************/
short OTime::operator ==( OTime otime )
{
short i;
if ( strcmp( date, otime.GetDate() ) == 0 &&
strcmp( time, otime.GetTime() ) == 0 )
{
i = 1;
}
else
{
i = 0;
}
return i;
}
/********************************************************************
Return Value:compare result
Parameters: OTime instance
********************************************************************/
short OTime::operator !=( OTime otime )
{
short i;
if ( strcmp( date, otime.GetDate() ) != 0 ||
strcmp( time, otime.GetTime() ) != 0 )
{
i = 1;
}
else
{
i = 0;
}
return i;
}
/********************************************************************
Return Value:compare result
Parameters: OTime instance
********************************************************************/
short OTime::operator <( OTime otime )
{
short j = strcmp( date, otime.GetDate() ) ;
if( j < 0 )
return 1 ;
else if( j == 0 )
{
j = strcmp( time, otime.GetTime() );
if( j < 0 )
return 1 ;
}
return 0 ;
}
/********************************************************************
Return Value:compare result
Parameters: OTime instance
********************************************************************/
short OTime::operator >( OTime otime )
{
short j = strcmp( date, otime.GetDate() ) ;
if( j > 0 )
return 1 ;
else if( j == 0 )
{
j = strcmp( time, otime.GetTime() );
if( j > 0 )
return 1 ;
}
return 0 ;
}
/********************************************************************
Return Value:compare result
Parameters: OTime instance
********************************************************************/
short OTime::operator <=( OTime otime )
{
short j = strcmp( date, otime.GetDate() ) ;
if( j <= 0 )
return 1 ;
else if( j == 0 )
{
j = strcmp( time, otime.GetTime() );
if( j <= 0 )
return 1 ;
}
return 0 ;
}
/********************************************************************
Return Value:compare result
Parameters: OTime instance
********************************************************************/
short OTime::operator >=( OTime otime )
{
short j = strcmp( date, otime.GetDate() ) ;
if( j >= 0 )
return 1 ;
else if( j == 0 )
{
j = strcmp( time, otime.GetTime() );
if( j >= 0 )
return 1 ;
}
return 0 ;
}
/********************************************************************
Return Value: year of this instance
Parameters: no
********************************************************************/
short OTime::GetYear( )
{
short yy;
sscanf( date, "%04hd", &yy );
return yy;
}
/********************************************************************
Return Value: month of this instance
Parameters: no
********************************************************************/
short OTime::GetMonth( )
{
short mm;
sscanf( date + 4, "%02hd", &mm );
return mm;
}
/********************************************************************
Return Value: date of this instance
Parameters: no
********************************************************************/
short OTime::GetDay( )
{
short dd;
sscanf( date + 6, "%02hd", &dd );
return dd;
}
/********************************************************************
Return Value: 0 is Sun,1 is Mon,...,6 is Sat.
Parameters: no
********************************************************************/
short OTime::GetDayofWeek( )
{
long total_day;
total_day = AbsDay( ) + 4;
short i = total_day % 7;
return i;
}
/********************************************************************
Return Value: hour of this instance
Parameters: no
********************************************************************/
short OTime::GetHour( )
{
short nh;
sscanf( time, "%02hd", &nh );
return nh;
}
/********************************************************************
Return Value: minute of this instance
Parameters: no
********************************************************************/
short OTime::GetMinute( )
{
short nf;
sscanf( time + 2, "%02hd", &nf );
return nf;
}
/********************************************************************
Return Value: second of this instance
Parameters: no
********************************************************************/
short OTime::GetSecond( )
{
short ns;
sscanf( time, "%02hd", &ns );
return ns;
}
/********************************************************************
Return Value: pointer of date
Parameters: no
********************************************************************/
char* OTime::GetDate()
{
return date;
}
/********************************************************************
Return Value: pointer of time
Parameters: no
********************************************************************/
char* OTime::GetTime()
{
return time;
}
short OTime::AddMonth( short months ) //加上多少月,成功返回1,否则返回0
{
short year = GetYear() + months/12 ;
months = months % 12 ;
short month = GetMonth();
if( month + months > 12 )
{
year ++ ;
month = month + months -12 ;
}
else
{
month += months ;
}
sprintf( date,"%04hd%02hd%02hd",year,month,GetDay() ) ;
return 1 ;
}
short OTime::MinusMonth( short months ) //减去多少月,成功返回1,否则返回0
{
short year = GetYear() - months / 12 ;
months = months % 12 ;
short month = GetMonth();
if( month - months > 0 )
{
month -= months ;
}
else
{
year --;
month = month + 12 - months ;
}
sprintf( date,"%04hd%02hd%02hd",year,month,GetDay() ) ;
return 1 ;
}
short OTime::AddYear( short year ) //加上多少月,成功返回1,否则返回0
{
sprintf( date,"%04hd%02hd%02hd",GetYear()+ year,GetMonth(),GetDay() ) ;
return 1 ;
}
short OTime::MinusYear( short year ) //减去多少月,成功返回1,否则返回0
{
sprintf( date,"%04hd%02hd%02hd",GetYear()- year,GetMonth(),GetDay() ) ;
return 1 ;
}
short OTime::AddDay( short day ) //加上多少天,成功返回1,否则返回0
{
OTimeSpan cltime_span( 1, 0 );
long total_day;
total_day = AbsDay( ) + cltime_span.GetDay( );
AbsToDate( total_day );
return 1 ;
}
short OTime::MinusDay( short day ) //减去多少天,成功返回1,否则返回0
{
OTimeSpan cltime_span( 1, 0 );
long total_day;
total_day = AbsDay( ) - cltime_span.GetDay( );
AbsToDate( total_day );
return 1 ;
}
/********************************************************************
Return Value: pointer of date
Parameters: no
********************************************************************/
char* OTime::GetFormatedDate()
{
memcpy( fmtdate,date, 4 ) ;
fmtdate[ 4 ] = '-' ;
memcpy( fmtdate + 5, date + 4, 2 ) ;
fmtdate[ 7 ] = '-' ;
memcpy( fmtdate + 8, date + 6, 2 ) ;
fmtdate[ 10 ] = NULL ;
return fmtdate;
}
/********************************************************************
Return Value: pointer of time
Parameters: no
********************************************************************/
char* OTime::GetFormatedTime()
{
memcpy( fmttime, time, 2 ) ;
fmttime[ 2 ] = ':' ;
memcpy( fmttime + 3, time + 2, 2 ) ;
fmttime[ 5 ] = ':' ;
memcpy( fmttime + 6, time + 4, 2 ) ;
fmttime[ 8 ] = NULL ;
return fmttime;
}
/********************************************************************
Return Value: 1
Parameters: pointer of date and time
********************************************************************/
void OTime::GetLocalTime ( )
{
GetLocalTime_CXX( GetDate(), GetTime() ) ;
}
/********************************************************************
Return Value: no
Parameters: no
********************************************************************/
void OTime::GetSystemTime()
{
ReadTime( GetDate(), GetTime() ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -