📄 vmdatetime.cpp
字号:
/*****************************************************************************/
/* SOURCE FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: Implementation of the VMTimeOffset and VMDateTime classes.
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/
#include "../../../stdafx.h"
#include "VMDateTime.h"
const int ciMaxTimeBufferSize = 520;
const int ciSafeTimeBufferSize = 500;
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::VMTimeOffset
DESCRIPTION: ctor.
INPUT: lSpan - the number of seconds in the time span
OUTPUT: none
RETURNS: none
*/
VMTimeOffset::VMTimeOffset( long lSpan )
{
m_lTimeSpan = lSpan;
}
/* End of function "VMTimeOffset::VMTimeOffset"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::VMTimeOffset
DESCRIPTION: ctor
INPUT: lDays - number of days in the time span
iHours - number of hourse in the time span
iMins - number of minutes in the time span
iSecs - number of seconds in the time span
OUTPUT:
RETURNS: none
*/
VMTimeOffset::VMTimeOffset( long lDays, int iHours, int iMins, int iSecs )
{
m_lTimeSpan = iSecs + 60 * ( iMins + 60 * ( iHours + 24 * lDays ) );
}
/* End of function "VMTimeOffset::VMTimeOffset"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::VMTimeOffset
DESCRIPTION: copy ctor
INPUT: roOther - another instance to set this up by
OUTPUT: none
RETURNS: none
*/
VMTimeOffset::VMTimeOffset( const VMTimeOffset& roOther )
{
m_lTimeSpan = roOther.m_lTimeSpan;
}
/* End of function "VMTimeOffset::VMTimeOffset"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator=
DESCRIPTION: assignment ctor
INPUT: roOther - another instance to set this up by
OUTPUT: none
RETURNS: this
*/
const VMTimeOffset& VMTimeOffset::operator= ( const VMTimeOffset& roOther )
{
m_lTimeSpan = roOther.m_lTimeSpan;
return( *this );
}
/* End of function ""
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetDays
DESCRIPTION: return the number of days in this span
INPUT: void
OUTPUT: none
RETURNS: long
*/
long VMTimeOffset::GetDays( void ) const
{
return( m_lTimeSpan / ( 24 * 3600L ) );
}
/* End of function "VMTimeOffset::GetDays"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::IsModByDaysZero
DESCRIPTION: determines if a time span has an exact number of days
(i.e., no hours, minutes and/or seconds remainder after
counting days)
INPUT: void
OUTPUT: none
RETURNS: true if mod minutes is zero
*/
bool VMTimeOffset::IsModByDaysZero( void ) const
{
return( ( m_lTimeSpan % ( 24 * 3600L ) ) == 0 );
}
/* End of function "VMTimeOffset::IsModByDaysZero"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetTotalHours
DESCRIPTION: return the total number of hours in this time span
INPUT: void
OUTPUT: none
RETURNS: long
*/
long VMTimeOffset::GetTotalHours( void ) const
{
return( m_lTimeSpan / 3600 );
}
/* End of function "VMTimeOffset::GetTotalHours"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetHours
DESCRIPTION: return the number of hours "over the days" in this time span
INPUT: void
OUTPUT: none
RETURNS: int
*/
int VMTimeOffset::GetHours( void ) const
{
return( (int)( GetTotalHours() - GetDays() * 24 ) );
}
/* End of function "VMTimeOffset::GetHours"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::IsModByHoursZero
DESCRIPTION: determines if a time span has an exact number of hours
(i.e., no minutes and/or seconds remainder after counting
hours)
INPUT: void
OUTPUT: none
RETURNS: true if mod minutes is zero
*/
bool VMTimeOffset::IsModByHoursZero( void ) const
{
return( ( m_lTimeSpan % 3600 ) == 0 );
}
/* End of function "VMTimeOffset::IsModByHoursZero"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetTotalMinutes
DESCRIPTION: return the total number of minutes in this time span
INPUT: void
OUTPUT: none
RETURNS: long
*/
long VMTimeOffset::GetTotalMinutes( void ) const
{
return( m_lTimeSpan / 60 );
}
/* End of function "VMTimeOffset::GetTotalMinutes"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::IsModByMinutesZero
DESCRIPTION: determines if a time span has an exact number of minutes
(i.e., no seconds remainder after counting minutes)
INPUT: void
OUTPUT: none
RETURNS: true if mod minutes is zero
*/
bool VMTimeOffset::IsModByMinutesZero( void ) const
{
return( 0 == ( m_lTimeSpan % 60 ) );
}
/* End of function "VMTimeOffset::IsModByMinutesZero"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetMinutes
DESCRIPTION: reutrn the number of minutes "over the hours" in the this
INPUT: void
OUTPUT: none
RETURNS: int
*/
int VMTimeOffset::GetMinutes( void ) const
{
return( (int)( GetTotalMinutes() - GetTotalHours() * 60 ) );
}
/* End of function "VMTimeOffset::GetMinutes"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetTotalSeconds
DESCRIPTION: returns the total seconds in this time span
INPUT: void
OUTPUT: none
RETURNS: long
*/
long VMTimeOffset::GetTotalSeconds( void ) const
{
return( m_lTimeSpan );
}
/* End of function "VMTimeOffset::GetTotalSeconds"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::GetSeconds
DESCRIPTION: return the number of seconds 'over the minutes' in this
INPUT: none
OUTPUT: none
RETURNS: int
*/
int VMTimeOffset::GetSeconds() const
{
return( (int)( GetTotalSeconds() - GetTotalMinutes() * 60 ) );
}
/* End of function "VMTimeOffset::GetSeconds"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator-
DESCRIPTION: subtraction operator
INPUT: oOther - the time span to subtract from this
OUTPUT: none
RETURNS: VMTimeOffset representing the difference
*/
VMTimeOffset VMTimeOffset::operator- ( VMTimeOffset oOther ) const
{
return( VMTimeOffset( m_lTimeSpan - oOther.m_lTimeSpan ) );
}
/* End of function "VMTimeOffset::operator-"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator+
DESCRIPTION: addition operator
INPUT: oOther - the time span to add to this
OUTPUT: none
RETURNS: VMTimeOffset representing the sum
*/
VMTimeOffset VMTimeOffset::operator+ ( VMTimeOffset oOther ) const
{
return( VMTimeOffset( m_lTimeSpan + oOther.m_lTimeSpan ) );
}
/* End of function "VMTimeOffset::operator+"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator+=
DESCRIPTION: addition operator
INPUT: oOther - the time span to add to this
OUTPUT: none
RETURNS: new value of this representing the sum
*/
const VMTimeOffset& VMTimeOffset::operator+= ( VMTimeOffset oOther )
{
m_lTimeSpan += oOther.m_lTimeSpan;
return( *this );
}
/* End of function "VMTimeOffset::operator+="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator-=
DESCRIPTION: subtraction operator
INPUT: oOther - the time span to subtract from this
OUTPUT: none
RETURNS: new value of this representing the difference
*/
const VMTimeOffset& VMTimeOffset::operator-= ( VMTimeOffset oOther )
{
m_lTimeSpan -= oOther.m_lTimeSpan;
return( *this );
}
/* End of function "VMTimeOffset::operator-="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator==
DESCRIPTION: equality operator
INPUT: oOther - the time span to compare to this
OUTPUT: none
RETURNS: true if equal false if not
*/
bool VMTimeOffset::operator== ( VMTimeOffset oOther ) const
{
return( m_lTimeSpan == oOther.m_lTimeSpan );
}
/* End of function "VMTimeOffset::operator=="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator!=
DESCRIPTION: inequality operator
INPUT: oOther - the time span to compare to this
OUTPUT: none
RETURNS: true if not-equal false if they are
*/
bool VMTimeOffset::operator!= ( VMTimeOffset oOther ) const
{
return( m_lTimeSpan != oOther.m_lTimeSpan );
}
/* End of function "VMTimeOffset::operator!="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator<
DESCRIPTION: less than operator
INPUT: oOther - the time span to compare to this
OUTPUT: none
RETURNS: true if this is less
*/
bool VMTimeOffset::operator< ( VMTimeOffset oOther ) const
{
return( m_lTimeSpan < oOther.m_lTimeSpan );
}
/* End of function "VMTimeOffset::operator<"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator>
DESCRIPTION: greater than operator
INPUT: oOther - the time span to compare to this
OUTPUT: none
RETURNS: true if this is more
*/
bool VMTimeOffset::operator> ( VMTimeOffset oOther ) const
{
return( m_lTimeSpan > oOther.m_lTimeSpan );
}
/* End of function "VMTimeOffset::operator>"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator<=
DESCRIPTION: less than or equal to operator
INPUT: oOther - the time span to compare to this
OUTPUT: none
RETURNS: true if this is less or equal
*/
bool VMTimeOffset::operator<= ( VMTimeOffset oOther ) const
{
return( m_lTimeSpan <= oOther.m_lTimeSpan );
}
/* End of function "VMTimeOffset::operator<="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMTimeOffset::operator>=
DESCRIPTION: greater than or equal to operator
INPUT: oOther - the time span to compare to this
OUTPUT: none
RETURNS: true if this is more or equal
*/
bool VMTimeOffset::operator>= ( VMTimeOffset oOther ) const
{
return( m_lTimeSpan >= oOther.m_lTimeSpan );
}
/* End of function "VMTimeOffset::operator>="
/*****************************************************************************/
///////////////////////////////////////////////////////////////////////////////
//
// The Implementation of the DateTime class follows below
//
///////////////////////////////////////////////////////////////////////////////
/*****************************************************************************/
/*
FUNCTION NAME: VMDateTime::CurrentTime
DESCRIPTION: static function to return an instance of this init'ized
to 'now'
INPUT: void -
OUTPUT: none
RETURNS: VMDateTime
*/
VMDateTime VMDateTime::CurrentTime( void )
{
SYSTEMTIME xNow;
// Find the current system time
//
GetLocalTime( &xNow );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -