void NDateTime::addMinutes(const nint minutes) { nint _minutes = minutes; while (getMinute() * _minutes > 59) { _minutes -= 60; addHours(1); } while (getMinute() + _minutes < 0) { _minutes += 60; addHours(-1); } m_Time.addMinutes(_minutes); }
Date Date::addMinutes(long minutes) { long hours = (getMm()+minutes)/60; minutes = (getMm()+minutes)%60; Date d = addHours(hours); d.setMm(minutes); 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 CDateTime::addMinutes(int add) { // Date inférieure if (add < 0) { for (int i = 0; i > add; --i) { // Heure précédente if (m_minute == 0) { addHours(-1); m_minute = 59; } else { --m_minute; } } } // Date supérieure else if (add > 0) { for (int i = 0; i < add; ++i) { // Heure suivante if (m_minute == 59) { addHours(1); m_minute = 0; } else { ++m_minute; } } } }
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; }
Time::Time(unsigned int hours, unsigned int mins, unsigned int secs) { addHours(hours); addMins(mins); addSecs(secs); }