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

📄 xdate.cpp

📁 一个通讯管理机的源代码。比较好用。推荐
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************///! Short description./*!  \param Date8*/int xbDate::SetDate( const char * Date8 ){  if( DateIsValid( Date8 ))  {    cDate8 = Date8;    return 1;  }  return 0;}/***************************************************************///! Short description./*!  \param Date8*//* this returns the number of days since 1/1/1900              */long xbDate::JulianDays( const char * Date8 ) const{   int year = YearOf( Date8 );   if(( year < EPOCH_MIN ) || (year >= EPOCH_MAX))     return XB_INVALID_DATE;/*   long days = DAYS_AD(year) - DAYS_AD(EPOCH_MIN);*/   long days = 0;   for (long y = EPOCH_MIN; y < year; y++ )     days += 365 + ( ( ( y%4==0 && y%100!=0 ) || y%400==0 ) ? 1 : 0 );   days += (long) DayOf( XB_FMT_YEAR, Date8 ) -1;   return days;}/***************************************************************///! Short description./*!  \param days*//* this function does the opposite of the JulianDays function  *//* it converts a julian based date into a Date8 format         */xbString& xbDate::JulToDate8( long days ){   char Date8[9];   int year, leap, month;   year = EPOCH_MIN;   leap = 0;               /* EPOCH_MIN of 100 is not a leap year *//* this while loop calculates the year of the date by incrementing   the years counter as it decrements the days counter */   while( days > ( 364+leap ))   {      days -= 365+leap;      year++;      if(( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 )         leap = 1;      else          leap = 0;   }    /*   for( i = 12, month = 0; i >= 1 && month == 0; i-- )   {      if( leap && days >= (long) AggregatedDaysInMonths[1][i] )      {         month = i;         days -= AggregatedDaysInMonths[1][i]-1;      }      else if( !leap && days >= (long) AggregatedDaysInMonths[0][i] )      {         month = i;         days -= AggregatedDaysInMonths[0][i]-1;      }   }   sprintf( Date8, "%4d%02d%02ld", year, month, days );*/ /* this for loop calculates the month and day of the date by   comparing the number of days remaining to one of the tables   */   for( month = 12; month >= 1; month-- )     if( days >= (long)AggregatedDaysInMonths[leap][month] ) {       days -= AggregatedDaysInMonths[leap][month];       break;     }   sprintf( Date8, "%4d%02d%02ld", year, month+1, days+1 );   Date8[8] = 0x00;   cDate8 = Date8;   return cDate8;}/***************************************************************///! Short description./*!  \param Date8*//* this routine returns a pointer to the day of the week(Sun-Sat)*/xbString& xbDate::CharDayOf( const char * Date8 ){  fDate = strdup( *Days[DayOf(XB_FMT_WEEK, Date8)]);  return fDate;}/***************************************************************///! Short description./*!  \param Date8*//* this routine returns a pointer to the month                 */xbString& xbDate::CharMonthOf( const char * Date8 ){  fDate = strdup( *Months[MonthOf( Date8 )-1]);  return( fDate );}/***************************************************************///! Short description./*!  \param Format  \param Date8*//* This function formats a date and returns a pointer to a     *//* static buffer containing the date                           */xbString& xbDate::FormatDate( const char * Format, const char * Date8 ){   const char *FmtPtr;     /* format pointer */   char *BufPtr;           /* buffer pointer */   char type;   char cbuf[10];   int  type_ctr, i;   char buf[50];   xbString s;   memset( buf, 0x00, 50 );   if( strstr( Format, "YYDDD" ))   {      buf[0] = Date8[2];      buf[1] = Date8[3];      sprintf( buf+2, "%03d", DayOf( XB_FMT_YEAR, Date8 ));   }   else   {      BufPtr = buf;      FmtPtr = Format;      memset( cbuf, 0x00, 10 );      while( *FmtPtr )      {         if( *FmtPtr != 'D' && *FmtPtr != 'M' && *FmtPtr != 'Y' )         {            *BufPtr = *FmtPtr;            BufPtr++;            FmtPtr++;         }         else         {             type = *FmtPtr;            type_ctr = 0;            while( *FmtPtr == type )            {               type_ctr++;               FmtPtr++;            }            switch( type )            {               case 'D':                           if( type_ctr == 1 )                  {                     sprintf( cbuf, "%d", DayOf( XB_FMT_MONTH, Date8 ));                     strcat( buf, cbuf );                     BufPtr += strlen( cbuf );                  }                  else if( type_ctr == 2 )                  {                     cbuf[0] = Date8[6];                     cbuf[1] = Date8[7];                     cbuf[2] = 0x00;                     strcat( buf, cbuf );                     BufPtr += 2;                  }                  else                  {                     s = CharDayOf( Date8 );                     if( type_ctr == 3 )                     {                        strncat( buf, s.getData(), 3 );                        BufPtr += 3;                        }                     else                     {                        strcpy( cbuf, CharDayOf( Date8 ));                        for( i = 0; i < 9; i++ )                           if( cbuf[i] == 0x20 ) cbuf[i] = 0x00;                        strcat( buf, cbuf );                        BufPtr += strlen( cbuf );                     }                  }                           break;               case 'M':                  if( type_ctr == 1 )                  {                     sprintf( cbuf, "%d", MonthOf( Date8 ));                     strcat( buf, cbuf );                     BufPtr += strlen( cbuf );                  }                  else if( type_ctr == 2 )                  {                     cbuf[0] = Date8[4];                     cbuf[1] = Date8[5];                     cbuf[2] = 0x00;                     strcat( buf, cbuf );                     BufPtr += 2;                  }                  else                  {                     s = CharMonthOf( Date8 );                     if( type_ctr == 3 )                     {                        strncat( buf, s.getData(), 3 );                        BufPtr += 3;                     }                     else                     {                        strcpy( cbuf, CharMonthOf( Date8 ));                        for( i = 0; i < 9; i++ )                           if( cbuf[i] == 0x20 ) cbuf[i] = 0x00;                        strcat( buf, cbuf );                        BufPtr += strlen( cbuf );                     }                  }                  break;                           case 'Y':                  if( type_ctr == 2 )                  {                     cbuf[0] = Date8[2];                     cbuf[1] = Date8[3];                     cbuf[2] = 0x00;                     strcat( buf, cbuf );                     BufPtr += 2;                  }                  else if( type_ctr == 4 )                  {                     cbuf[0] = Date8[0];                     cbuf[1] = Date8[1];                     cbuf[2] = Date8[2];                     cbuf[3] = Date8[3];                     cbuf[4] = 0x00;                     strcat( buf, cbuf );                     BufPtr += 4;                  }                  break;               default:                  break;            }         }      }   }   fDate = buf;   return fDate;}/***************************************************************///! Short description./*!  \param Date8*//* this routine returns the Date8 format of the last day of the   month for the given input Date8 */ xbString & xbDate::LastDayOfMonth( const char * Date8 ){  char tmp[9];  sprintf( tmp, "%4.4d%2.2d%2.2d",      YearOf( Date8 ), MonthOf( Date8 ),      DaysInMonths[IsLeapYear(Date8)][MonthOf(Date8)]);  cDate8 = tmp;  return cDate8;}/**********************************************************************///! Short description./*!*/xbString &xbDate::operator+=( int count ){  JulToDate8( JulianDays() + count );  return cDate8;}/**********************************************************************///! Short description./*!*/xbString &xbDate::operator-=( int count ){  JulToDate8( JulianDays() - count );  return cDate8;}/**********************************************************************///! Short description./*!*/xbString &xbDate::operator++( int ){  *this+=1;  return cDate8;}/**********************************************************************///! Short description./*!*/xbString &xbDate::operator--( int ){  *this-=1;  return cDate8;}/**********************************************************************///! Short description./*!*/xbString &xbDate::operator+( int count ){  xbDate d( GetDate() );  d+=count;  fDate = d.GetDate();  return fDate;}/**********************************************************************///! Short description./*!*/xbString &xbDate::operator-( int count ){  xbDate d( GetDate() );  d-=count;  fDate = d.GetDate();  return fDate;}/**********************************************************************///! Short description./*!*/long xbDate::operator-( const xbDate & d ) const {  return JulianDays() - d.JulianDays();}/**********************************************************************///! Short description./*!*/int xbDate::operator==( const xbDate & d ) const {  if( JulianDays() == d.JulianDays() )    return 1;  else    return 0;}/**********************************************************************///! Short description./*!*/int xbDate::operator!=( const xbDate & d ) const {  if( JulianDays() != d.JulianDays() )     return 1;  else     return 0;}/**********************************************************************///! Short description./*!*/int xbDate::operator<( const xbDate & d ) const {  if( JulianDays() < d.JulianDays() )     return 1;  else     return 0;}/**********************************************************************///! Short description./*!*/int xbDate::operator>( const xbDate & d ) const {  if( JulianDays() > d.JulianDays() )     return 1;  else     return 0;}/**********************************************************************///! Short description./*!*/int xbDate::operator<=( const xbDate & d ) const {  if( JulianDays() <= d.JulianDays() )     return 1;  else     return 0;}/**********************************************************************///! Short description./*!*/int xbDate::operator>=( const xbDate & d ) const {  if( JulianDays() >= d.JulianDays() )     return 1;  else     return 0;}/**********************************************************************/

⌨️ 快捷键说明

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