예제 #1
0
// set the value of a property
qbool oDateTime::setProperty(qlong pPropID,EXTfldval &pNewValue,EXTCompInfo* pECI) {
	// most anum properties are managed by Omnis but some we need to do ourselves, no idea why...
	
	switch (pPropID) {
		case oDT_localtime: {
			datestamptype omnisstamp;
			qbool success;
			pNewValue.getDate(omnisstamp, dpFdtimeC, &success);
			
			if (success) {
				struct tm timestruct;
				
				OmnisToTimeStruct(omnisstamp, timestruct);
				
				setTimestamp(mktime(&timestruct));
			};
			return qtrue;
		}; break;
		case oDT_utctime: {
			datestamptype omnisstamp;
			qbool success;
			pNewValue.getDate(omnisstamp, dpFdtimeC, &success);
			
			if (success) {
				struct tm timestruct;
				
				OmnisToTimeStruct(omnisstamp, timestruct);
				
#ifdef iswin32
				setTimestamp(_mkgmtime(&timestruct));
#else
				setTimestamp(timegm(&timestruct));
#endif
			};
			return qtrue;
		}; break;
		default:
			return oBaseNVComponent::setProperty(pPropID, pNewValue, pECI);
			break;
	};
};
예제 #2
0
// Get an ISO 8601 Formatted Date String from EXTFldVal
std::string OmnisTools::getISO8601DateStringFromEXTFldVal(EXTfldval& fVal) {
	datestamptype theDate;
	std::string retString;
	std::stringstream sin;
	
	fVal.getDate(theDate, dpFdtimeC);
	FieldValType theType = getType(fVal);
    
	if (theType.valType != fftDate)
		return "";
    
	// Set date part of string
    if (theDate.mDateOk == qtrue
        && !(theType.valSubType == dpFdtime1900
             || theType.valSubType == dpFdtime1980
             || theType.valSubType == dpFdtime2000
             || theType.valSubType == dpFdtimeC
             || theType.valSubType == dpFtime))
    {	
        sin << int(theDate.mYear);
        if (theDate.mMonth < 10) {
            sin << "-0" << int(theDate.mMonth);
        } else {
            sin << "-" << int(theDate.mMonth);
        } 
        if (theDate.mDay < 10) {
            sin << "-0" << int(theDate.mDay);
        } else {
            sin << "-" << int(theDate.mDay);
        } 
	}
	
	// Set time part of string
    if (theDate.mTimeOk == qtrue
        && !(theType.valSubType == dpFdate1900
             || theType.valSubType == dpFdate1900
             || theType.valSubType == dpFdate1980
             || theType.valSubType == dpFdate2000
             || theType.valSubType == dpFdtime1900
             || theType.valSubType == dpFdtime1980
             || theType.valSubType == dpFdtime2000
             || theType.valSubType == dpFdtimeC))
    {
        sin << "T";
        if (theDate.mHour < 10) {
            sin << "0" << int(theDate.mHour);
        } else {
            sin << int(theDate.mHour);
        }
        if (theDate.mMin < 10) {
            sin << ":0" << int(theDate.mMin);
        } else {
            sin << ":" << int(theDate.mMin);
        }
        if (theDate.mSecOk) {
            if (theDate.mSec < 10) {
                sin << ":0" << int(theDate.mSec);
            } else {
                sin << ":" << int(theDate.mSec);
            }
        }
        // NOTE: Even though Omnis contains hundredths data, it is not part of
        //       the ISO8601 format
    }
    
    // Place string into return value
    retString = sin.str();
	
	return retString;
}
예제 #3
0
// This method sets up the passed in EXTfldval with a date representing the ISO8601 Date passed in
void OmnisTools::getEXTfldvalFromISO8601DateString(EXTfldval& fVal, std::string dateString) {

    boost::smatch theMatch;
    datestamptype theDate;
    
    if( boost::regex_match(dateString,theMatch,datetimeCheck) ) { 
        // Match date/time
        fVal.setEmpty(fftDate, dpFdtimeC);
        fVal.getDate(theDate);
        
        theDate.mDateOk = qtrue;
        theDate.mYear = lexical_cast<qshort>(theMatch[1]);  // First match is year
        theDate.mMonth = (char) lexical_cast<qshort>(theMatch[2]);  // Second match is month
        theDate.mDay = (char) lexical_cast<qshort>(theMatch[3]);  // Third match is day
        
        theDate.mTimeOk = qtrue;
        theDate.mHour = (char) lexical_cast<qshort>(theMatch[4]);  // Fourth match is hour
        theDate.mMin = (char) lexical_cast<qshort>(theMatch[5]);  // Fifth match is minute
        
        theDate.mSecOk = qfalse;
        theDate.mHunOk = qfalse;
        
        // Optional matches
        if (theMatch[6].matched && theMatch[6].length() > 0) {
            // Appears to have the seconds portion
            theDate.mSecOk = qtrue;
            theDate.mSec = lexical_cast<int>(theMatch[6]);  // Sixth match is seconds
        }
        
        fVal.setDate(theDate, dpFdtimeC);
        
    } else if ( boost::regex_match(dateString,theMatch,dateCheck) ) {
        // Match date
        fVal.setEmpty(fftDate, dpFdate2000);
        fVal.getDate(theDate);
        
        theDate.mDateOk = qtrue;
        theDate.mYear = lexical_cast<qshort>(theMatch[1]);  // First match is year
        theDate.mMonth = (char) lexical_cast<qshort>(theMatch[2]);  // Second match is month
        theDate.mDay = (char) lexical_cast<qshort>(theMatch[3]);  // Third match is day
        
        theDate.mTimeOk = qfalse;
        theDate.mSecOk = qfalse;
        theDate.mHunOk = qfalse;
        
        fVal.setDate(theDate, dpFdate2000);
        
    } else if ( boost::regex_match(dateString,theMatch,timeCheck) ) {
        // Match time
        fVal.setEmpty(fftDate, dpFtime);
        fVal.getDate(theDate);
        
        theDate.mDateOk = qfalse;
        theDate.mTimeOk = qtrue;
        theDate.mHour = (char) lexical_cast<qshort>(theMatch[1]);  // First match is hour
        theDate.mMin = (char) lexical_cast<qshort>(theMatch[2]);  // Second match is minute
        
        theDate.mSecOk = qfalse;
        theDate.mHunOk = qfalse;
        
        // Optional matches
        if (theMatch[3].matched && theMatch[3].length() > 0) {
            // Appears to have the seconds portion
            theDate.mSecOk = qtrue;
            theDate.mSec = (char) lexical_cast<qshort>(theMatch[3]);  // Third match is seconds
        }
        
        fVal.setDate(theDate);
    }
}