void NDateTime::addSeconds(const nint seconds) { nint _seconds = seconds; while (getSecond() * _seconds > 59) { _seconds -= 60; addMinutes(1); } while (getSecond() + _seconds < 0) { _seconds += 60; addMinutes(-1); } m_Time.addSeconds(_seconds); }
void CDateTime::addSeconds(int add) { if (add == 0) return; // On ajoute les jours entiers séparemment pour alléger les calculs int days = add / 86400; if (days) addDays(days); add %= 86400; if (add < 0) { for (int i = 0; i > add; --i) { // Minute précédente if (m_second == 0) { addMinutes(-1); m_second = 59; } else { --m_second; } } } // Date supérieure else if (add > 0) { for (int i = 0; i < add; ++i) { // Minute suivante if (m_second == 59) { addMinutes(1); m_second = 0; } else { ++m_second; } } } }
Date Date::addSeconds(long seconds) { long minutes = (getSs()+seconds)/60; seconds = (getSs()+seconds)%60; Date d = addMinutes(minutes); d.setSs(seconds); return d; }
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; }