version 1.20, 2002/05/09 21:08:55
|
version 1.21, 2002/05/14 04:57:48
|
|
|
static const char _NULL_INTERVAL_TYPE_STRING[] = "00000000000000.000000:000"; | static const char _NULL_INTERVAL_TYPE_STRING[] = "00000000000000.000000:000"; |
static const char _NULL_DATE_TYPE_STRING[] = "00000000000000.000000-000"; | static const char _NULL_DATE_TYPE_STRING[] = "00000000000000.000000-000"; |
| |
|
class CIMDateTimeRep |
|
{ |
|
public: |
|
enum { FORMAT_LENGTH = 25 }; |
|
|
|
// |
|
// Length of the string required to store only the date and time without |
|
// the UTC sign and UTC offset. |
|
// Format is yyyymmddhhmmss. |
|
// Note : The size does not include the null byte. |
|
// |
|
enum { DATE_TIME_LENGTH = 14 }; |
|
|
|
// |
|
// Length of the string required to store the formatted date and time |
|
// Format is yyyy:mm:dd:hh:mm:ss. |
|
// |
|
enum { FORMATTED_DATE_TIME = 20 }; |
|
|
|
char data[FORMAT_LENGTH + 1]; |
|
}; |
|
|
|
|
CIMDateTime::CIMDateTime() | CIMDateTime::CIMDateTime() |
{ | { |
|
_rep = new CIMDateTimeRep(); |
clear(); | clear(); |
} | } |
| |
CIMDateTime::CIMDateTime(const char* str) | CIMDateTime::CIMDateTime(const char* str) |
{ | { |
set(str); |
_rep = new CIMDateTimeRep(); |
|
if (!_set(str)) |
|
{ |
|
delete _rep; |
|
throw BadDateTimeFormat(); |
|
} |
} | } |
| |
CIMDateTime::CIMDateTime(const CIMDateTime& x) | CIMDateTime::CIMDateTime(const CIMDateTime& x) |
{ | { |
memcpy(_rep, x._rep, sizeof(_rep)); |
_rep = new CIMDateTimeRep(); |
|
memcpy(_rep->data, x._rep->data, sizeof(_rep->data)); |
} | } |
| |
CIMDateTime& CIMDateTime::operator=(const CIMDateTime& x) | CIMDateTime& CIMDateTime::operator=(const CIMDateTime& x) |
{ | { |
if (&x != this) | if (&x != this) |
memcpy(_rep, x._rep, sizeof(_rep)); |
memcpy(_rep->data, x._rep->data, sizeof(_rep->data)); |
| |
return *this; | return *this; |
} | } |
| |
CIMDateTime::~CIMDateTime() | CIMDateTime::~CIMDateTime() |
{ | { |
|
delete _rep; |
} | } |
| |
Boolean CIMDateTime::isNull() const | Boolean CIMDateTime::isNull() const |
{ | { |
return strcmp(_rep, _NULL_INTERVAL_TYPE_STRING) == 0; |
return strcmp(_rep->data, _NULL_INTERVAL_TYPE_STRING) == 0; |
} | } |
| |
const char* CIMDateTime::getString() const | const char* CIMDateTime::getString() const |
{ | { |
return _rep; |
return _rep->data; |
} | } |
| |
void CIMDateTime::clear() | void CIMDateTime::clear() |
{ | { |
strcpy(_rep, _NULL_INTERVAL_TYPE_STRING); |
strcpy(_rep->data, _NULL_INTERVAL_TYPE_STRING); |
} | } |
| |
Boolean CIMDateTime::_set(const char* str) | Boolean CIMDateTime::_set(const char* str) |
|
|
| |
// Be sure the incoming string is the proper length: | // Be sure the incoming string is the proper length: |
| |
if (strlen(str) != FORMAT_LENGTH) |
if (strlen(str) != CIMDateTimeRep::FORMAT_LENGTH) |
return false; | return false; |
| |
// Determine the type (date or interval); examine the 21st character; | // Determine the type (date or interval); examine the 21st character; |
|
|
| |
// Check to see if other characters are digits: | // Check to see if other characters are digits: |
| |
for (Uint32 i = 0; i < FORMAT_LENGTH; i++) |
for (Uint32 i = 0; i < CIMDateTimeRep::FORMAT_LENGTH; i++) |
{ | { |
if (i != DOT_OFFSET && i != SIGN_OFFSET && !isdigit(str[i])) | if (i != DOT_OFFSET && i != SIGN_OFFSET && !isdigit(str[i])) |
return false; | return false; |
|
|
if (seconds > 59) | if (seconds > 59) |
return false; | return false; |
| |
memcpy(_rep, str, sizeof(_rep)); |
memcpy(_rep->data, str, sizeof(_rep->data)); |
| |
return true; | return true; |
} | } |
|
|
throw BadDateTimeFormat(); | throw BadDateTimeFormat(); |
} | } |
| |
|
CIMDateTime CIMDateTime::clone() const |
|
{ |
|
return CIMDateTime(*this); |
|
} |
|
|
PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMDateTime& x) | PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMDateTime& x) |
{ | { |
return os << x.getString(); | return os << x.getString(); |
|
|
| |
Boolean operator==(const CIMDateTime& x, const CIMDateTime& y) | Boolean operator==(const CIMDateTime& x, const CIMDateTime& y) |
{ | { |
return memcmp(x._rep, y._rep, sizeof(x._rep)) == 0; |
return memcmp(x._rep->data, y._rep->data, sizeof(x._rep->data)) == 0; |
} | } |
| |
void CIMDateTime::formatDateTime(char* dateTimeStr, tm* tm) | void CIMDateTime::formatDateTime(char* dateTimeStr, tm* tm) |
|
|
// | // |
// Copy only the Start date and time in to the dateTimeOnly string | // Copy only the Start date and time in to the dateTimeOnly string |
// | // |
dateTimeOnly = new char [FORMATTED_DATE_TIME]; |
dateTimeOnly = new char [CIMDateTimeRep::FORMATTED_DATE_TIME]; |
strncpy( dateTimeOnly, startDateTimeCString, DATE_TIME_LENGTH ); |
strncpy( dateTimeOnly, startDateTimeCString, CIMDateTimeRep::DATE_TIME_LENGTH ); |
dateTimeOnly[DATE_TIME_LENGTH] = 0; |
dateTimeOnly[CIMDateTimeRep::DATE_TIME_LENGTH] = 0; |
formatDateTime(dateTimeOnly ,&tmvalStart); | formatDateTime(dateTimeOnly ,&tmvalStart); |
| |
// | // |
// Copy only the Finish date and time in to the dateTimeOnly string | // Copy only the Finish date and time in to the dateTimeOnly string |
// | // |
strncpy( dateTimeOnly, finishDateTimeCString, DATE_TIME_LENGTH ); |
strncpy( dateTimeOnly, finishDateTimeCString, CIMDateTimeRep::DATE_TIME_LENGTH ); |
dateTimeOnly[DATE_TIME_LENGTH] = 0; |
dateTimeOnly[CIMDateTimeRep::DATE_TIME_LENGTH] = 0; |
formatDateTime( dateTimeOnly, &tmvalFinish ); | formatDateTime( dateTimeOnly, &tmvalFinish ); |
| |
// Convert local time to seconds since the epoch | // Convert local time to seconds since the epoch |