-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: WeekTime object to calculate the total time in one week.
- Loading branch information
Showing
7 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "WeekTime.h" | ||
|
||
#include <QObject> | ||
#include <QString> | ||
|
||
namespace Model | ||
{ | ||
WeekTime::WeekTime( QObject* pParent_ ) : QObject( pParent_ ) {} | ||
|
||
bool WeekTime::addTime( int timeMs_ ) | ||
{ | ||
if ( timeMs_ > INT_MAX || ( m_totalTimeMs + timeMs_ ) > INT_MAX ) | ||
{ | ||
return false; | ||
} | ||
|
||
m_totalTimeMs += timeMs_; | ||
return true; | ||
} | ||
|
||
int WeekTime::getTime() const | ||
{ | ||
return m_totalTimeMs; | ||
} | ||
|
||
void WeekTime::reset() | ||
{ | ||
m_totalTimeMs = 0; | ||
} | ||
|
||
QString weekTimeToString( const WeekTime& weekTime_ ) | ||
{ | ||
const int msInHour = 1000 * 60 * 60; | ||
const int msInMinutes = 1000 * 60; | ||
|
||
const int& timeMs = weekTime_.getTime(); | ||
const int hours = timeMs / msInHour; | ||
int rest = timeMs - ( hours * msInHour ); | ||
|
||
const int minutes = rest / msInMinutes; | ||
|
||
QString timeString = QString::number( hours ) + "h" + QString::number( minutes ); | ||
|
||
const QStringList& timeStrings = timeString.split( "h" ); | ||
if ( timeStrings.size() > 1 && timeStrings[ 1 ] == "0" ) | ||
{ | ||
timeString.append( "0" ); | ||
} | ||
|
||
return timeString; | ||
} | ||
|
||
} // namespace Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
#include <QString> | ||
|
||
namespace Model | ||
{ | ||
class WeekTime : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
WeekTime( QObject* pParent_ = Q_NULLPTR ); | ||
~WeekTime() = default; | ||
|
||
bool addTime( int timeMs_ ); | ||
|
||
int getTime() const; | ||
|
||
void reset(); | ||
|
||
private: | ||
int m_totalTimeMs = 0; | ||
}; | ||
|
||
QString weekTimeToString( const WeekTime& weekTime_ ); | ||
} // namespace Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers | ||
// such as names of functions and macros. | ||
// For more information see https://go.microsoft.com/fwlink/?linkid=865984 | ||
#define INT_MAX |