Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace {
- QString makeDuration(uint32_t timeoutSeconds)
- {
- const int week = 604800;
- const int day = 86400;
- const int hour = 3600;
- const int minute = 60;
- const int second = 1;
- QString text;
- uint32_t copy = timeoutSeconds;
- if(timeoutSeconds > 0){
- unsigned int count = timeoutSeconds / week;
- timeoutSeconds -= week * count;
- if (count > 0){
- if (count > 1){
- text.append(QString::number(count) + " weeks ");
- }
- else
- {
- text.append(QString::number(count) + " week ");
- }
- }
- }
- if(timeoutSeconds > 0){
- unsigned int count = timeoutSeconds / day;
- timeoutSeconds -= day * count;
- if (count > 0){
- if (count > 1){
- text.append(QString::number(count) + " days ");
- }
- else
- {
- text.append(QString::number(count) + " day ");
- }
- }
- }
- if(timeoutSeconds > 0){
- unsigned int count = timeoutSeconds / hour;
- timeoutSeconds -= hour * count;
- if (count > 0){
- if (count > 1){
- text.append(QString::number(count) + " hours ");
- }
- else
- {
- text.append(QString::number(count) + " hour ");
- }
- }
- }
- if(timeoutSeconds > 0){
- unsigned int count = timeoutSeconds / minute;
- timeoutSeconds -= minute * count;
- if (count > 0){
- if (count > 1){
- text.append(QString::number(count) + " minutes ");
- }
- else
- {
- text.append(QString::number(count) + " minute ");
- }
- }
- }
- if(timeoutSeconds > 0){
- unsigned int count = timeoutSeconds / second;
- timeoutSeconds -= second * count;
- if (count > 0){
- if (count > 1){
- text.append(QString::number(count) + " seconds ");
- }
- else
- {
- text.append(QString::number(count) + " second ");
- }
- }
- }
- if(copy > 60){
- text.append("(" + QString::number(copy) + " seconds)");
- }
- return text;
- }
- } // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement