⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otimespan.cpp

📁 联通接收发送新程序
💻 CPP
字号:

/* Copyright(C) 2000 by JiangSu Bell Software CO.,LTD. */
/*
****************************************************************************
Content:        Implementation of class OTimeSpan
Name:           otimespan.cpp		        Version: 1.0.0
Created by:     CaoGuiRong       		Date: 2000-08-23
Comment:

All rights reserved
****************************************************************************
*/


#include "otimespan.h"
#include "otime.h"
#include "iostream.h"


/********************************************************************
  构造函数
********************************************************************/
OTimeSpan::OTimeSpan()
{
}
/********************************************************************
  构造函数
  Parameters: an existed instance
********************************************************************/
OTimeSpan::OTimeSpan( OTimeSpan& otimespan )
{
  m_lday    = otimespan.GetDay();
  m_lsecond = otimespan.GetSecondinDay();
}
/********************************************************************
  构造函数
  Return Value: no
  Parameters: components of a timespan
********************************************************************/
OTimeSpan::OTimeSpan( const long lsecond )
{
  SetSecond( lsecond ) ;
}
/********************************************************************
  构造函数
  Return Value: no
  Parameters: components of a timespan
********************************************************************/
OTimeSpan::OTimeSpan( const long lday, const long lsecond )
{
  Set( lday, lsecond ) ;
}
/********************************************************************
  析构函数
  Return Value: no
  Parameters: no
********************************************************************/
OTimeSpan::~OTimeSpan()
{
}
/********************************************************************
  设总秒数
  Return Value: no
  Parameters: timespan value, in
********************************************************************/
void OTimeSpan::SetSecond( const long lsecond )
{
  m_lday     = lsecond / SECOND_OF_DAY ;
  m_lsecond  = lsecond % SECOND_OF_DAY ;
}
/********************************************************************
  设置时间长度
  Return Value: 1 if parameters are valid
                0 if parameters are invalid
  Parameters:   lday  , number of days
                shour , number of hours remainder
                smin  , number of minutes remainder
                scec  , number of seconds remainder
********************************************************************/
short OTimeSpan::Set( const long day, const short shour ,const short smin, const short ssec )
{
  if ( shour >= 0 && shour <= 23 &&
       smin  >= 0 && smin  <= 59 &&
       ssec  >= 0 && ssec  <= 59   )
  {
    m_lday    = day ;
    m_lsecond = shour * SECOND_OF_HOUR   +
                smin  * SECOND_OF_MINUTE +
                ssec;
    return 1 ;
  }
  else
  {
    //cout<<"\r\nTimespan Error!"<<flush;
    return 0 ;
  }
}
/********************************************************************
  设置时间长度
  Return Value: 1 if parameters are valid
                0 if parameters are invalid
  Parameters:   lday  , number of days
                shour , number of hours remainder
                smin  , number of minutes remainder
                scec  , number of seconds remainder
********************************************************************/
short OTimeSpan::Set(const long day,const long second )
{
  m_lday    = day ;
  m_lsecond = second ;
  if (  second >= 0 && second <= SECOND_OF_DAY   )
  {
    return 1 ;
  }
  else
  {
    //cout<<"\r\nTimespan Error!"<<flush;
    return 0 ;
  }
}


/********************************************************************
  Return Value:otimespan instance
  Parameters: OTime instance to be minus
********************************************************************/
OTimeSpan operator - ( OTime otime1, OTime otime2 )
{
  long lday    = otime1.AbsDay( )    - otime2.AbsDay( ) ;
  long lsecond = otime1.AbsSecond( ) - otime2.AbsSecond( );

  while( lsecond < 0 )
  {
    lday    -- ;
    lsecond += SECOND_OF_DAY;
  }

  OTimeSpan otimespan( lday , lsecond ) ;

  return otimespan ;
}

/********************************************************************
  返回总共有多少小时
  Return Value: total hours of this instance
  Parameters: no
********************************************************************/
long OTimeSpan::GetTotalHour( )
{
  return m_lday * HOUR_OF_DAY +   m_lsecond / SECOND_OF_HOUR ;
}
/********************************************************************
  返回总共有多少分钟
  Return Value: total minutes of this instance
  Parameters: no
********************************************************************/
long OTimeSpan::GetTotalMinute(  )
{
  return m_lday * MINUTE_OF_DAY + m_lsecond / SECOND_OF_MINUTE ;
}
/********************************************************************
  Return Value: total seconds of this instance
  Parameters: no
********************************************************************/
long OTimeSpan::GetTotalSecond(  )
{
  return m_lday * SECOND_OF_DAY + m_lsecond  ;
}
/********************************************************************
  返回总共有多少天
  Return Value: total days of this instance
  Parameters: no
********************************************************************/
long OTimeSpan::GetDay( )
{
  return m_lday ;
}
/********************************************************************
  Return Value: hours of current day
  Parameters: no
********************************************************************/
long OTimeSpan::GetHour( )
{
  return m_lsecond / SECOND_OF_HOUR ;
}
/********************************************************************
  Version Date:
  Return Value: minutes of current hour
  Parameters: no
********************************************************************/
long OTimeSpan::GetMinute(  )
{
  long l = m_lsecond % SECOND_OF_HOUR;
  return l / SECOND_OF_MINUTE;
}
/********************************************************************
  Return Value: seconds of current minute
  Parameters: no
********************************************************************/
long OTimeSpan::GetSecond(  )
{
  return m_lsecond % SECOND_OF_MINUTE;
}
/********************************************************************
  Return Value: seconds of current minute
  Parameters: no
********************************************************************/
long OTimeSpan::GetSecondinDay(  )
{
  return m_lsecond ;
}
/********************************************************************
  Return Value:a OTimeSpan instance
  Parameters:another instance to be added
********************************************************************/
OTimeSpan OTimeSpan::operator + (OTimeSpan otimespan )
{
  m_lday    += otimespan.GetDay() ;
  m_lsecond += otimespan.GetSecondinDay() ;

  m_lday    += m_lsecond / SECOND_OF_DAY ;
  m_lsecond =  m_lsecond % SECOND_OF_DAY ;
  return *this;
}
/********************************************************************
  Return Value: a OTimeSpan instance
  Parameters:another instance to be minus
********************************************************************/
OTimeSpan OTimeSpan::operator -(OTimeSpan otimespan )
{////????
  m_lday    -= otimespan.GetDay() ;
  m_lsecond -= otimespan.GetSecondinDay();

  while( m_lsecond < 0 )
  {
    m_lday -- ;
    m_lsecond += SECOND_OF_DAY ;
  }

  return *this;
}
/********************************************************************
  Return Value: a OTimeSpan instance
  Parameters:another instance to be minus
********************************************************************/
/*
OTimeSpan& OTimeSpan::operator = (OTimeSpan& otimespan )
{
  Set( otimespan.GetDay(),otimespan.GetSecondinDay() ) ;
  return *this;
}
*/
/********************************************************************
  Return Value: a OTimeSpan instance
  Parameters:another instance to be minus
********************************************************************/
OTimeSpan OTimeSpan::operator = (OTimeSpan otimespan )
{
  Set( otimespan.GetDay(),otimespan.GetSecondinDay() ) ;
  return *this;
}
/********************************************************************
  Return Value: a OTimeSpan instance
  Parameters: another instance to be  added
********************************************************************/
OTimeSpan& OTimeSpan::operator +=(OTimeSpan& otimespan )
{
  m_lday    += otimespan.GetDay() ;
  m_lsecond += otimespan.GetSecondinDay() ;

  m_lday    += m_lsecond / SECOND_OF_DAY ;
  m_lsecond =  m_lsecond % SECOND_OF_DAY ;
  return *this;
}
/********************************************************************
  Return Value: a OTimeSpan instance
  Parameters: another instance to be minus
********************************************************************/
OTimeSpan& OTimeSpan::operator -=(OTimeSpan& otimespan )
{
  m_lday    -= otimespan.GetDay() ;
  m_lsecond -= otimespan.GetSecondinDay() ;

  while( m_lsecond < 0 )
  {
    m_lday -- ;
    m_lsecond += SECOND_OF_DAY ;
  }
  return *this;
}
/********************************************************************
  Return Value: compare result
  Parameters:another OTimeSpan instance
********************************************************************/
short OTimeSpan::operator ==( OTimeSpan otimespan )
{
  if ( m_lday    == otimespan.GetDay() &&
       m_lsecond == otimespan.GetSecondinDay() )
  {
    return 1 ;
  }
  else
  {
    return 0 ;
  }
}
/********************************************************************
  Return Value: compare result
  Parameters:another OTimeSpan instance
********************************************************************/
short OTimeSpan::operator !=( OTimeSpan otimespan )
{
  if ( m_lday    != otimespan.GetDay() ||
       m_lsecond != otimespan.GetSecondinDay() )
  {
    return 1 ;
  }
  else
  {
    return 0 ;
  }
}
/********************************************************************
  Return Value: compare result
  Parameters:another OTimeSpan instance
********************************************************************/
short OTimeSpan::operator <( OTimeSpan otimespan )
{
  if ( m_lday <  otimespan.GetDay() ||
       ( (m_lday == otimespan.GetDay()) && (m_lsecond < otimespan.GetSecondinDay()) ) )
  {
    return 1 ;
  }
  else
  {
    return 0 ;
  }
}
/********************************************************************
  Return Value: compare result
  Parameters:another OTimeSpan instance
********************************************************************/
short OTimeSpan::operator >( OTimeSpan otimespan )
{
  if ( m_lday  > otimespan.GetDay() )
  {
    return 1 ;
  }
  else if( m_lday == otimespan.GetDay() && m_lsecond > otimespan.GetSecondinDay() )
  {
    return 1 ;
  }
  else
  {
    return 0 ;
  }
}
/********************************************************************
  Return Value: compare result
  Parameters:another OTimeSpan instance
********************************************************************/
short OTimeSpan::operator <=( OTimeSpan otimespan )
{
  if ( m_lday  > otimespan.GetDay() )
  {
    return 0 ;
  }
  else if( m_lday == otimespan.GetDay() && m_lsecond > otimespan.GetSecondinDay() )
  {
    return 0 ;
  }
  else
  {
    return 1 ;
  }
}
/********************************************************************
  Return Value: compare result
  Parameters:another OTimeSpan instance
********************************************************************/
short OTimeSpan::operator >=( OTimeSpan otimespan )
{
  if ( m_lday  > otimespan.GetDay() )
  {
    return 1 ;
  }
  else if( m_lday == otimespan.GetDay() && m_lsecond >= otimespan.GetSecondinDay() )
  {
    return 1 ;
  }
  else
  {
    return 0 ;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -