📄 vmdatetime.cpp
字号:
break;
case 'U':
case 'W':
{
int iWeekDayTemp;
int iTemp;
if ( aChar == 'W' )
{
if ( m_xTime.wDayOfWeek == 0 ) /* monday based */
iWeekDayTemp = 6;
else
iWeekDayTemp = m_xTime.wDayOfWeek - 1;
}
else
{
iWeekDayTemp = m_xTime.wDayOfWeek;
}
if ( m_iDayOfYear < iWeekDayTemp )
{
iTemp = 0;
}
else
{
iTemp = m_iDayOfYear / 7;
if ( ( m_iDayOfYear % 7 ) >= iWeekDayTemp )
iTemp++;
}
pchBuffer += sprintf( pchBuffer, "%02d", iTemp );
}
break;
case 'w':
pchBuffer += sprintf( pchBuffer, "%l", m_xTime.wDayOfWeek );
break;
case 'x':
pchBuffer += sprintf( pchBuffer, "%02u/%02u/%02u",
m_xTime.wMonth,
m_xTime.wDay,
m_xTime.wYear % 100 );
break;
case 'X':
pchBuffer += sprintf( pchBuffer, "%02u:%02u:%02u",
m_xTime.wHour,
m_xTime.wMinute,
m_xTime.wSecond );
break;
case 'y':
pchBuffer += sprintf( pchBuffer, "%02u", m_xTime.wYear % 100 );
break;
case 'Y':
pchBuffer += sprintf( pchBuffer, "%04u", m_xTime.wYear );
break;
case 'z':
case 'Z':
break;
}
}
else
{
*pchBuffer++ = aChar;
if ( _istlead( aChar ) )
{
assert( pchBuffer < &achBuffer[ ciMaxTimeBufferSize ] );
*pchBuffer++ = *pchFormat++;
}
}
}
*pchBuffer = '\0';
return( achBuffer );
}
/* End of function "VMDateTime::Format"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::SubtractOneMonth
DESCRIPTION: Subtracts a month to now and then will correct the date if
required
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMDateTime::SubtractOneMonth( void )
{
m_xTime.wMonth--;
if ( m_xTime.wMonth == 0 )
{
m_xTime.wMonth = 12;
}
switch( m_xTime.wMonth )
{
case 12: // January
{
m_xTime.wYear--;
}
break;
case 2:
{
if ( IsLeapYear( m_xTime.wYear ) )
{
if ( m_xTime.wDay > 29 )
{
m_xTime.wDay = 29;
}
}
else
if ( m_xTime.wDay > 28 )
{
m_xTime.wDay = 28;
}
}
break;
case 4:
case 6:
case 9:
case 11:
{
if ( m_xTime.wDay > 30 )
{
m_xTime.wDay = 30;
}
}
break;
}
SetDays();
}
/* End of function "VMDateTime::SubtractOneMonth"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::AddOneMonth
DESCRIPTION: Adds a month to now and then will correct the date if
required
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMDateTime::AddOneMonth( void )
{
m_xTime.wMonth++;
if ( m_xTime.wMonth == 13 )
{
m_xTime.wMonth = 1;
}
switch( m_xTime.wMonth )
{
case 1: // January
{
m_xTime.wYear++;
}
break;
case 4: // April
case 6: // June
case 9: // September
case 11: // November
{
if ( m_xTime.wDay > 30 )
{
m_xTime.wDay = 30;
}
}
break;
case 2:
{
if ( IsLeapYear( m_xTime.wYear ) )
{
if ( m_xTime.wDay > 29 )
{
m_xTime.wDay = 29;
}
}
else
if ( m_xTime.wDay > 28 )
{
m_xTime.wDay = 28;
}
}
break;
}
SetDays();
}
/* End of function "VMDateTime::AddOneMonth"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::SubtractOneYear
DESCRIPTION: Subtracts a year to now and then will correct the date if
required
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMDateTime::SubtractOneYear( void )
{
if ( IsLeapYear( m_xTime.wYear ) )
{
if ( m_xTime.wMonth == 2 && m_xTime.wDay == 29 )
{
m_xTime.wMonth = 3;
m_xTime.wDay = 1;
}
}
m_xTime.wYear -= 1;
SetDays();
}
/* End of function "VMDateTime::SubtractOneYear"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::AddOneYear
DESCRIPTION: Adds a year to now and then will correct the date if
required
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMDateTime::AddOneYear( void )
{
if ( IsLeapYear( m_xTime.wYear ) )
{
if ( m_xTime.wMonth == 2 && m_xTime.wDay == 29 )
{
m_xTime.wMonth = 3;
m_xTime.wDay = 1;
}
}
m_xTime.wYear += 1;
SetDays();
}
/* End of function "VMDateTime::AddOneYear"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator==
DESCRIPTION: equality operator
INPUT: roOther - another instance to compare this to
OUTPUT: none
RETURNS: true if the values are equal, false if not
*/
bool VMDateTime::operator== ( VMDateTime roOther ) const
{
if ( memcmp( &m_xTime, &roOther.m_xTime, sizeof( SYSTEMTIME ) ) )
{
return( FALSE );
}
else
{
return( TRUE );
}
}
/* End of function "VMDateTime::operator=="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator!=
DESCRIPTION: inequality operator
INPUT: roOther - another instance to compare this to
OUTPUT: none
RETURNS: true if the values are not equal, false if they are
*/
bool VMDateTime::operator!= ( VMDateTime oOther ) const
{
return ( ( *this == oOther ) ? FALSE : TRUE );
}
/* End of function "VMDateTime::operator!="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator<
DESCRIPTION: less than operator
INPUT: roOther - another instance to compare this to
OUTPUT: none
RETURNS: true if this is less, false if they are
*/
bool VMDateTime::operator< ( VMDateTime oOther ) const
{
if ( m_xTime.wYear < oOther.m_xTime.wYear )
{
return( TRUE );
}
else
{
double dblThisSeconds = ( m_iDayOfYear * ( 24 * 60 * 60 ) )
+ ( m_xTime.wHour * ( 60 * 60 ) )
+ ( m_xTime.wMinute * 60 )
+ m_xTime.wSecond;
double dblOtherSeconds = ( oOther.m_iDayOfYear * ( 24 * 60 * 60 ) )
+ ( oOther.m_xTime.wHour * ( 60 * 60 ) )
+ ( oOther.m_xTime.wMinute * 60 )
+ oOther.m_xTime.wSecond;
return ( dblThisSeconds < dblOtherSeconds );
}
}
/* End of function "VMDateTime::operator<"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator>
DESCRIPTION: greater than operator
INPUT: roOther - another instance to compare this to
OUTPUT: none
RETURNS: true if this is greater, false if they are
*/
bool VMDateTime::operator> ( VMDateTime oOther ) const
{
if ( m_xTime.wYear > oOther.m_xTime.wYear )
{
return( TRUE );
}
else
{
double dblThisSeconds = ( m_iDayOfYear * ( 24 * 60 * 60 ) )
+ ( m_xTime.wHour * ( 60 * 60 ) )
+ ( m_xTime.wMinute * 60 )
+ m_xTime.wSecond;
double dblOtherSeconds = ( oOther.m_iDayOfYear * ( 24 * 60 * 60 ) )
+ ( oOther.m_xTime.wHour * ( 60 * 60 ) )
+ ( oOther.m_xTime.wMinute * 60 )
+ oOther.m_xTime.wSecond;
return ( dblThisSeconds > dblOtherSeconds );
}
}
/* End of function "VMDateTime::operator>"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator<=
DESCRIPTION: less than or equal to operator
INPUT: roOther - another instance to compare this to
OUTPUT: none
RETURNS: true if this is less or equal, false if they are
*/
bool VMDateTime::operator<= ( VMDateTime oOther ) const
{
return( ( *this < oOther ) || ( *this == oOther ) );
}
/* End of function "VMDateTime::operator<="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator>=
DESCRIPTION: greater than or equal to operator
INPUT: roOther - another instance to compare this to
OUTPUT: none
RETURNS: true if this is greater or equal, false if they are
*/
bool VMDateTime::operator>= ( VMDateTime oOther ) const
{
return( ( *this > oOther ) || ( *this == oOther ) );
}
/* End of function "VMDateTime::operator>="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator=
DESCRIPTION: assignment operator
INPUT: roOther - another instance to set the value of this from
OUTPUT: none
RETURNS: this
*/
const VMDateTime& VMDateTime::operator= ( const VMDateTime& roOther )
{
m_xTime = roOther.m_xTime;
SetDays();
return( *this );
}
/* End of function "VMDateTime::operator="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::operator=
DESCRIPTION: assignment from SYSTEMTIME
INPUT: xTime -
OUTPUT: none
RETURNS: this
*/
const VMDateTime& VMDateTime::operator=( SYSTEMTIME xTime )
{
m_xTime = xTime;
SetDays();
return( *this );
}
/* End of function "VMDateTime::operator="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::GetTime
DESCRIPTION:
INPUT: void
OUTPUT: none
RETURNS: SYSTEMTIME
*/
SYSTEMTIME VMDateTime::GetTime( void ) const
{
return( m_xTime );
}
/* End of function "VMDateTime::GetTime"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::GetYear
DESCRIPTION:
INPUT: void
OUTPUT: none
RETURNS: int
*/
int VMDateTime::GetYear( void ) const
{
return( m_xTime.wYear );
}
/* End of function "VMDateTime::GetYear"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::GetMonth
DESCRIPTION:
INPUT: void
OUTPUT: none
RETURNS: int
*/
int VMDateTime::GetMonth( void ) const
{
return( m_xTime.wMonth );
}
/* End of function "VMDateTime::GetMonth"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::GetDay
DESCRIPTION:
INPUT: void
OUTPUT: none
RETURNS: int
*/
int VMDateTime::GetDay( void ) const
{
return( m_xTime.wDay );
}
/* End of function "VMDateTime::GetDay"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::GetHour
DESCRIPTION:
INPUT: void
OUTPUT: none
RETURNS: int
*/
int VMDateTime::GetHour( void ) const
{
return( m_xTime.wHour );
}
/* End of function "VMDateTime::GetHour"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::GetMinute
DESCRIPTION:
INPUT: void
OUTPUT: none
RETURNS: int
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -