version 1.67, 2006/02/03 19:07:53
|
version 1.68, 2006/05/17 19:32:27
|
|
|
| |
| |
/* This method does not change the value of object, it only converts the | /* This method does not change the value of object, it only converts the |
representation form one time zone to the time zone specified. |
representation to a specified time zone. |
@param cdt Time Stamp object that will be converted |
@param utc utc-offset in minutes that represents the time zone to be |
@param utc uct-offset in minutes that represents the time zone to be |
converted to. |
converted to |
|
Returns a copy of the calling object modified to represent the same |
|
time in a different time zone. |
|
*/ | */ |
void CIMDateTime::setUtcOffSet(Sint32 utc) | void CIMDateTime::setUtcOffSet(Sint32 utc) |
{ | { |
if(this->isInterval()){ |
PEGASUS_ASSERT(!isInterval()); |
return; |
|
} |
|
| |
MessageLoaderParms parmsOv("Common.CIMDateTime.UTC_OVERFLOW", | MessageLoaderParms parmsOv("Common.CIMDateTime.UTC_OVERFLOW", |
"overflow has occurred during conversion to UTC"); | "overflow has occurred during conversion to UTC"); |
|
|
"underflow has occurred during conversion to UTC"); | "underflow has occurred during conversion to UTC"); |
| |
// convert CIMDateTime to microseconds. | // convert CIMDateTime to microseconds. |
Uint64 cdt_MicroSec = this->toMicroSeconds(); |
Uint64 origMicroseconds = toMicroSeconds(); |
Uint32 offSet = abs(utc); |
Sint64 newUtcMicroseconds = utc * _ONE_MINUTE; |
Uint64 offSet_hor = (offSet/60) * _ONE_HOUR; |
Uint64 newMicroseconds = origMicroseconds - newUtcMicroseconds; |
Uint64 offSet_min = (offSet%60) * _ONE_MINUTE; |
|
Uint64 cdt_MicroSecSum = 0; |
|
String sgn_offset; |
|
|
|
//Add (if utc is - ) or subtract (if utc is +) utc to/from DateTime. |
|
if (utc >= 0) { |
|
if (cdt_MicroSec < (offSet_hor + offSet_min)) { |
|
throw DateTimeOutOfRangeException(parmsOv); |
|
} |
|
cdt_MicroSecSum = cdt_MicroSec - (offSet_hor + offSet_min); |
|
sgn_offset = "+"; |
|
} |
|
| |
else{ |
// Check for underflow or overflow |
if (_TEN_THOUSAND_YEARS < (cdt_MicroSec + offSet_hor + offSet_min)) { |
if (utc >= 0) |
|
{ |
|
if (origMicroseconds < (Uint64)newUtcMicroseconds) |
|
{ |
throw DateTimeOutOfRangeException(parmsUn); | throw DateTimeOutOfRangeException(parmsUn); |
} | } |
cdt_MicroSecSum = cdt_MicroSec + (offSet_hor + offSet_min); |
} |
sgn_offset = "-"; |
else |
|
{ |
|
if (_TEN_THOUSAND_YEARS < (origMicroseconds - newUtcMicroseconds)) |
|
{ |
|
throw DateTimeOutOfRangeException(parmsOv); |
|
} |
} | } |
| |
|
// Create a new CIMDateTime with the recalculated microseconds value |
|
// and use the specified UTC value. |
|
CIMDateTime newDateTime = CIMDateTime(newMicroseconds, false); |
|
|
|
char newUtcBuffer[5]; |
|
sprintf(newUtcBuffer, "%+04d", utc); |
|
Boolean res = newDateTime._rep->set_utcOffSet(newUtcBuffer); |
| |
//Create new DateTime from sum of old DateTime and UTC and set UCT of new Date time. |
if (!res) |
CIMDateTime ans = CIMDateTime(cdt_MicroSecSum, false); |
{ |
|
|
char utcBuff [5]; |
|
sprintf(utcBuff, "%03d", offSet); |
|
String utc_str = sgn_offset.append(String(utcBuff)); |
|
Boolean res = ans._rep->set_utcOffSet(utc_str); |
|
|
|
if (res) { |
|
this->_rep->copy(ans._rep); // set_utcOffSet worked |
|
return; |
|
} |
|
else{ |
|
Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2, | Tracer::trace(__FILE__,__LINE__,TRC_CIM_DATA,Tracer::LEVEL2, |
"CIMDateTime::setUTCOffSet() failed"); | "CIMDateTime::setUTCOffSet() failed"); |
throw InvalidDateTimeFormatException(); | throw InvalidDateTimeFormatException(); |
} | } |
|
|
|
this->_rep->copy(newDateTime._rep); |
} | } |
| |
| |