kplato
KPlato::Duration Class Reference
The Duration class can be used to store a timespan in a convenient format. More...
#include <kptduration.h>
Public Types | |
| enum | Format { Format_DayTime, Format_Year, Format_Month, Format_Week, Format_Day, Format_Hour, Format_HourFraction, Format_i18nDayTime, Format_i18nYear, Format_i18nMonth, Format_i18nWeek, Format_i18nDay, Format_i18nHour, Format_i18nHourFraction } |
| enum | Unit { Unit_Y, Unit_M, Unit_w, Unit_d, Unit_h, Unit_m, Unit_s, Unit_ms } |
Public Member Functions | |
| Duration (double value, Unit unit=Unit_ms) | |
| Duration (const qint64 value, Unit=Unit_ms) | |
| Duration (unsigned d, unsigned h, unsigned m, unsigned s=0, unsigned ms=0) | |
| Duration (const Duration &d) | |
| Duration () | |
| ~Duration () | |
| void | addDays (qint64 delta) |
| void | addHours (qint64 delta) |
| void | addMilliseconds (qint64 delta) |
| void | addMinutes (qint64 delta) |
| void | addSeconds (qint64 delta) |
| unsigned | days () const |
| QString | format (Unit unit=Unit_h, int presition=1, const KLocale *locale=0) const |
| void | get (unsigned *days, unsigned *hours, unsigned *minutes, unsigned *seconds=0, unsigned *milliseconds=0) const |
| unsigned | hours () const |
| qint64 | milliseconds () const |
| qint64 | minutes () const |
| bool | operator!= (qint64 d) const |
| bool | operator!= (const Duration &d) const |
| Duration | operator* (const Duration value) const |
| Duration | operator* (const double value) const |
| Duration | operator* (int value) const |
| Duration | operator+ (const Duration &d) const |
| Duration & | operator+= (const Duration &d) |
| Duration | operator- (const Duration &d) const |
| Duration & | operator-= (const Duration &d) |
| double | operator/ (const Duration &d) const |
| Duration | operator/ (int value) const |
| bool | operator< (qint64 d) const |
| bool | operator< (const Duration &d) const |
| bool | operator<= (qint64 d) const |
| bool | operator<= (const Duration &d) const |
| Duration & | operator= (const Duration &d) |
| bool | operator== (qint64 d) const |
| bool | operator== (const Duration &d) const |
| bool | operator> (qint64 d) const |
| bool | operator> (const Duration &d) const |
| bool | operator>= (qint64 d) const |
| bool | operator>= (const Duration &d) const |
| qint64 | seconds () const |
| double | toDouble (Unit u=Unit_ms) const |
| QString | toString (Format format=Format_DayTime) const |
Static Public Member Functions | |
| static Duration | fromString (const QString &s, Format format=Format_DayTime, bool *ok=0) |
| static Unit | unitFromString (const QString &unit) |
| static QStringList | unitList (bool trans=false) |
| static QString | unitToString (Duration::Unit unit, bool trans=false) |
| static bool | valueFromString (const QString &value, double &rv, Unit &unit) |
Static Public Attributes | |
| static const Duration | zeroDuration |
Protected Member Functions | |
| void | copy (const Duration &d) |
Detailed Description
The Duration class can be used to store a timespan in a convenient format.
The timespan can be in length in many many hours down to milliseconds.
Definition at line 39 of file kptduration.h.
Member Enumeration Documentation
DayTime = d hh:mm:ss.sss Day = d.ddd Hour = hh:mm HourFraction = h.fraction of an hour.
- Enumerator:
Definition at line 48 of file kptduration.h.
Definition at line 51 of file kptduration.h.
Constructor & Destructor Documentation
| KPlato::Duration::Duration | ( | ) |
Definition at line 37 of file kptduration.cpp.
| KPlato::Duration::Duration | ( | const Duration & | d | ) |
Definition at line 52 of file kptduration.cpp.
| KPlato::Duration::Duration | ( | unsigned | d, | |
| unsigned | h, | |||
| unsigned | m, | |||
| unsigned | s = 0, |
|||
| unsigned | ms = 0 | |||
| ) |
Definition at line 56 of file kptduration.cpp.
| KPlato::Duration::Duration | ( | const qint64 | value, | |
| Duration::Unit | unit = Unit_ms | |||
| ) | [explicit] |
Definition at line 64 of file kptduration.cpp.
| KPlato::Duration::Duration | ( | double | value, | |
| Duration::Unit | unit = Unit_ms | |||
| ) | [explicit] |
Definition at line 41 of file kptduration.cpp.
| KPlato::Duration::~Duration | ( | ) |
Definition at line 76 of file kptduration.cpp.
Member Function Documentation
| void KPlato::Duration::addDays | ( | qint64 | delta | ) | [inline] |
Adds delta to *this.
If delta > *this, *this is set to zeroDuration.
Definition at line 83 of file kptduration.h.
| void KPlato::Duration::addHours | ( | qint64 | delta | ) | [inline] |
Adds delta to *this.
If delta > *this, *this is set to zeroDuration.
Definition at line 78 of file kptduration.h.
| void KPlato::Duration::addMilliseconds | ( | qint64 | delta | ) | [inline] |
Adds delta to *this.
If delta > *this, *this is set to zeroDuration.
Definition at line 63 of file kptduration.h.
| void KPlato::Duration::addMinutes | ( | qint64 | delta | ) | [inline] |
Adds delta to *this.
If delta > *this, *this is set to zeroDuration.
Definition at line 73 of file kptduration.h.
| void KPlato::Duration::addSeconds | ( | qint64 | delta | ) | [inline] |
Adds delta to *this.
If delta > *this, *this is set to zeroDuration.
Definition at line 68 of file kptduration.h.
| void KPlato::Duration::copy | ( | const Duration & | d | ) | [protected] |
Definition at line 349 of file kptduration.cpp.
| unsigned KPlato::Duration::days | ( | ) | const [inline] |
Return duration in whole days.
Definition at line 94 of file kptduration.h.
| QString KPlato::Duration::format | ( | Unit | unit = Unit_h, |
|
| int | presition = 1, |
|||
| const KLocale * | locale = 0 | |||
| ) | const |
Format duration into a string with unit and presition using locale. If locale == 0, uses KGLobal::locale.
Definition at line 144 of file kptduration.cpp.
| Duration KPlato::Duration::fromString | ( | const QString & | s, | |
| Format | format = Format_DayTime, |
|||
| bool * | ok = 0 | |||
| ) | [static] |
Create a duration from string s with format.
Definition at line 235 of file kptduration.cpp.
| void KPlato::Duration::get | ( | unsigned * | days, | |
| unsigned * | hours, | |||
| unsigned * | minutes, | |||
| unsigned * | seconds = 0, |
|||
| unsigned * | milliseconds = 0 | |||
| ) | const |
Convert duration into days, hours, minutes, seconds and milliseconds.
Definition at line 280 of file kptduration.cpp.
| unsigned KPlato::Duration::hours | ( | ) | const [inline] |
Return duration in whole hours.
Definition at line 92 of file kptduration.h.
| qint64 KPlato::Duration::milliseconds | ( | ) | const [inline] |
Return duration in milliseconds.
Definition at line 86 of file kptduration.h.
| qint64 KPlato::Duration::minutes | ( | ) | const [inline] |
Return duration in whole minutes.
Definition at line 90 of file kptduration.h.
| bool KPlato::Duration::operator!= | ( | qint64 | d | ) | const [inline] |
Definition at line 101 of file kptduration.h.
| bool KPlato::Duration::operator!= | ( | const Duration & | d | ) | const [inline] |
Definition at line 100 of file kptduration.h.
Definition at line 130 of file kptduration.cpp.
| Duration KPlato::Duration::operator* | ( | const double | value | ) | const |
Definition at line 124 of file kptduration.cpp.
| Duration KPlato::Duration::operator* | ( | int | value | ) | const |
Definition at line 102 of file kptduration.cpp.
Add duration with duration d.
Definition at line 119 of file kptduration.h.
Add duration with duration d.
Definition at line 122 of file kptduration.h.
Subtract duration with duration d.
Definition at line 124 of file kptduration.h.
Subtract duration with duration d.
Definition at line 127 of file kptduration.h.
| double KPlato::Duration::operator/ | ( | const Duration & | d | ) | const |
Divide duration with the duration d.
Definition at line 136 of file kptduration.cpp.
| Duration KPlato::Duration::operator/ | ( | int | value | ) | const |
Divide duration with the integer value.
Definition at line 113 of file kptduration.cpp.
| bool KPlato::Duration::operator< | ( | qint64 | d | ) | const [inline] |
Definition at line 103 of file kptduration.h.
| bool KPlato::Duration::operator< | ( | const Duration & | d | ) | const [inline] |
Definition at line 102 of file kptduration.h.
| bool KPlato::Duration::operator<= | ( | qint64 | d | ) | const [inline] |
Definition at line 105 of file kptduration.h.
| bool KPlato::Duration::operator<= | ( | const Duration & | d | ) | const [inline] |
Definition at line 104 of file kptduration.h.
Definition at line 110 of file kptduration.h.
| bool KPlato::Duration::operator== | ( | qint64 | d | ) | const [inline] |
Definition at line 99 of file kptduration.h.
| bool KPlato::Duration::operator== | ( | const Duration & | d | ) | const [inline] |
Definition at line 98 of file kptduration.h.
| bool KPlato::Duration::operator> | ( | qint64 | d | ) | const [inline] |
Definition at line 107 of file kptduration.h.
| bool KPlato::Duration::operator> | ( | const Duration & | d | ) | const [inline] |
Definition at line 106 of file kptduration.h.
| bool KPlato::Duration::operator>= | ( | qint64 | d | ) | const [inline] |
Definition at line 109 of file kptduration.h.
| bool KPlato::Duration::operator>= | ( | const Duration & | d | ) | const [inline] |
Definition at line 108 of file kptduration.h.
| qint64 KPlato::Duration::seconds | ( | ) | const [inline] |
Return duration in whole seconds.
Definition at line 88 of file kptduration.h.
| double KPlato::Duration::toDouble | ( | Unit | u = Unit_ms |
) | const [inline] |
Converts Duration into a double and scales it to unit u.
Definition at line 139 of file kptduration.h.
Convert duration to a string with format.
Definition at line 154 of file kptduration.cpp.
| Duration::Unit KPlato::Duration::unitFromString | ( | const QString & | unit | ) | [static] |
Definition at line 321 of file kptduration.cpp.
| QStringList KPlato::Duration::unitList | ( | bool | trans = false |
) | [static] |
Definition at line 302 of file kptduration.cpp.
| QString KPlato::Duration::unitToString | ( | Duration::Unit | unit, | |
| bool | trans = false | |||
| ) | [static] |
Definition at line 316 of file kptduration.cpp.
Returns value and unit from a <unit> coded string in rv and unit.
Definition at line 331 of file kptduration.cpp.
Member Data Documentation
const Duration KPlato::Duration::zeroDuration [static] |
This is useful for occasions where we need a zero duration.
Definition at line 158 of file kptduration.h.
The documentation for this class was generated from the following files:
