void NDateTime::addMilliSeconds(const nint milliseconds) { nint _milliseconds = milliseconds; while (getMillisecond() * _milliseconds > 999) { _milliseconds -= 1000; addSeconds(1); } while (getMillisecond() + _milliseconds < 0) { _milliseconds += 1000; addSeconds(-1); } m_Time.addMilliSeconds(_milliseconds); }
void Date::addTime(std::string time, std::string unit) { Split splt; // default for units: inherent units if( unit.size() == 0 ) unit = unitStr; // It is save to append units (even if empty) to time // Note: time-unit overrules parameter unit. time += unit; // Split string at positions where digits and characters alternate. splt.setSeparator(":alnum:"); splt = time ; // If there is a mix of digits and non-digits, splt.size() >= 2: // isNonDigit && size == 1 is an error. // size == 0 is an error. // But, for !isNonDigit && size == 1 we got the default bool isNon = ! hdhC::isDigit(time); if( (splt.size() == 1 && isNon) || (splt.size() == 0) ) { std::ostringstream ostr(std::ios::app); ostr << "Date::addTime()" << "\nerror in 2nd parameter (time=" << time << ")" ; exceptionError( ostr.str() ); } // unitStr and int strings are empty. // Pure digits are always converted to days. if( splt.size() == 1 ) { addDays( splt.toDouble(0) ) ; return; } std::string str(splt[1]); if( str[0] == 'y' ) addYears( splt.toDouble(0) ); else if( str.substr(0,2) == "mo" ) addMonths( splt.toDouble(0) ); else if( str[0] == 'd' ) addDays( splt.toDouble(0) ); else if( str[0] == 'h' ) addHours( splt.toDouble(0) ); else if( str.substr(0,2) == "mi" ) addMinutes( splt.toDouble(0) ); else if( str[0] == 's' ) addSeconds( splt.toDouble(0) ); return; }
void Date::addTime(double time, std::string unit) { if( unit.size() == 0 ) unit = unitStr; if( unit[0] == 'y' ) addYears( time ); else if( unit.substr(0,2) == "mo" ) addMonths( time ); else if( unit[0] == 'd' ) addDays( time ); else if( unit[0] == 'h' ) addHours( time ); else if( unit.substr(0,2) == "mi" ) addMinutes( time ); else if( unit[0] == 's' ) addSeconds( time ); else // the default addDays( time ); return; }
/** * Subtract a given number of seconds from this DateTime object. * @param seconds The number of seconds to subtract from this object. * @return A reference to this object. */ DateTime& operator-= (long seconds) { addSeconds(-seconds); return *this; }
bool CDateTime::addDays (int iDays) { unsigned int iSeconds = (iDays) * (_DAY) / _SECOND; return addSeconds (iSeconds); }
bool ossimLocalTm::setIso8601(const std::string& timeString, bool shiftToGmtOffsetZero) { ossimDate now; std::string::size_type pos = 0; ossim_int32 year = 0; ossim_int32 month = 0; ossim_int32 day = 0; ossim_int32 timeZoneOffset = 0; if(timeString[0] != 'T') // make sure it's not time only { // look for year // if(readIntegerFromString(year, timeString, pos, 4)) { // retrieved the year portion // now check for separator not digit // // we at least have a year // now check for others setYear(year); if(!isdigit(timeString[pos])) { // skip separator ++pos; } if(readIntegerFromString(month, timeString, pos, 2)) { setMonth(month); if(!isdigit(timeString[pos])) { // skip separator ++pos; } if(readIntegerFromString(day, timeString, pos, 2)) { setDay(day); } } } else { return false; } } else // set year month day to current { setYear(now.getYear()); setMonth(now.getMonth()); setDay(now.getDay()); } // check to see if we need to read time portion if(timeString[pos] == 'T') { ++pos; // skip T character ossim_int32 hours=0, minutes=0; if(readIntegerFromString(hours, timeString, pos, 2)) { setHour(hours); // now check for separator if(!std::isdigit(timeString[pos])) { ++pos; // skip separator if present } if(readIntegerFromString(minutes, timeString, pos, 2)) { setMin(minutes); // now check for time zone if only a hour minute time // if(timeString[pos] == 'Z') { std::time_t t = mktime(this); t += m_timezoneOffset*3600; setTimeGivenEpoc(t); } else if(!readTimeZoneOffset(timeZoneOffset, timeString, pos)) { double fractionalSeconds = 0.0; if(!std::isdigit(timeString[pos])) { ++pos; } std::string::size_type endPos = timeString.find_first_not_of("0123456789.", pos); if(endPos == std::string::npos) { fractionalSeconds = ossimString(timeString.begin()+pos, timeString.end()).toDouble(); } else { fractionalSeconds = ossimString(timeString.begin()+pos, timeString.begin()+endPos).toDouble(); } setFloatSec(fractionalSeconds); pos = endPos; if(pos == std::string::npos) { // we will not be too strict so if at the end then just return we got enough return true; } if(timeString[pos] == 'Z') { std::time_t t = mktime(this); t += m_timezoneOffset*3600; setTimeGivenEpoc(t); //std::cout << "OFFSET == " << m_timezoneOffset << std::endl; } else { readTimeZoneOffset(timeZoneOffset, timeString, pos); } } } } else { // need at least hours return false; } } else if(std::isdigit(timeString[pos])) { ossim_int32 hours=0, minutes=0; if(readIntegerFromString(hours, timeString, pos, 2)) { setHour(hours); // now check for separator if(!std::isdigit(timeString[pos])) { ++pos; // skip separator if present } if(readIntegerFromString(minutes, timeString, pos, 2)) { setMin(minutes); if(!readTimeZoneOffset(timeZoneOffset, timeString, pos)) { double fractionalSeconds = 0.0; if(!std::isdigit(timeString[pos])) { ++pos; } std::string::size_type endPos = timeString.find_first_not_of("0123456789.", pos); if(endPos == std::string::npos) { fractionalSeconds = ossimString(timeString.begin()+pos, timeString.end()).toDouble(); } else { fractionalSeconds = ossimString(timeString.begin()+pos, timeString.begin()+endPos).toDouble(); } setFloatSec(fractionalSeconds); pos = endPos; if(pos == std::string::npos) { // we will not be too strict so if at the end then just return we got enough return true; } if(timeString[pos] == 'Z') { // For proper readouts we need to shift // to current time zone of the system // //std::cout << "OFFSET == " << m_timezoneOffset << std::endl; std::time_t t = mktime(this); t += m_timezoneOffset*3600; setTimeGivenEpoc(t); } else { readTimeZoneOffset(timeZoneOffset, timeString, pos); } } } } } else { // need at least hours return false; } if(shiftToGmtOffsetZero && (timeZoneOffset!=0)) { addSeconds(-timeZoneOffset); } return true; }
Status KeyGenerator::generateNewKeysIfNeeded(OperationContext* opCtx) { if (MONGO_FAIL_POINT(disableKeyGeneration)) { return {ErrorCodes::FailPointEnabled, "key generation disabled"}; } auto currentTime = LogicalClock::get(opCtx)->getClusterTime(); auto keyStatus = _client->getNewKeys(opCtx, _purpose, currentTime); if (!keyStatus.isOK()) { return keyStatus.getStatus(); } const auto& newKeys = keyStatus.getValue(); auto keyIter = newKeys.cbegin(); LogicalTime currentKeyExpiresAt; long long keyId = currentTime.asTimestamp().asLL(); if (keyIter == newKeys.cend()) { currentKeyExpiresAt = addSeconds(currentTime, _keyValidForInterval); auto status = insertNewKey(opCtx, _client, keyId, _purpose, currentKeyExpiresAt); if (!status.isOK()) { return status; } keyId++; } else if (keyIter->getExpiresAt() < currentTime) { currentKeyExpiresAt = addSeconds(currentTime, _keyValidForInterval); auto status = insertNewKey(opCtx, _client, keyId, _purpose, currentKeyExpiresAt); if (!status.isOK()) { return status; } keyId++; ++keyIter; } else { currentKeyExpiresAt = keyIter->getExpiresAt(); ++keyIter; } // Create a new key in advance if we don't have a key on standby after the current one // expires. // Note: Convert this block into a loop if more reserved keys are desired. if (keyIter == newKeys.cend()) { auto reserveKeyExpiresAt = addSeconds(currentKeyExpiresAt, _keyValidForInterval); auto status = insertNewKey(opCtx, _client, keyId, _purpose, reserveKeyExpiresAt); if (!status.isOK()) { return status; } } else if (keyIter->getExpiresAt() < currentTime) { currentKeyExpiresAt = addSeconds(currentKeyExpiresAt, _keyValidForInterval); auto status = insertNewKey(opCtx, _client, keyId, _purpose, currentKeyExpiresAt); if (!status.isOK()) { return status; } } return Status::OK(); }