Advertisement
Lajamerr_Mittesdine

Timeout message length

Jul 11th, 2018
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace {
  2.  
  3.     QString makeDuration(uint32_t timeoutSeconds)
  4.     {
  5.         const int week      = 604800;
  6.         const int day       = 86400;
  7.         const int hour      = 3600;
  8.         const int minute    = 60;
  9.         const int second    = 1;
  10.         QString text;
  11.         uint32_t copy = timeoutSeconds;
  12.  
  13.         if(timeoutSeconds > 0){
  14.             unsigned int count = timeoutSeconds / week;
  15.             timeoutSeconds -= week * count;
  16.             if (count > 0){
  17.                 if (count > 1){
  18.                     text.append(QString::number(count) + " weeks ");
  19.                 }
  20.                 else
  21.                 {
  22.                     text.append(QString::number(count) + " week ");
  23.                 }
  24.             }
  25.         }
  26.  
  27.         if(timeoutSeconds > 0){
  28.             unsigned int count = timeoutSeconds / day;
  29.             timeoutSeconds -= day * count;
  30.             if (count > 0){
  31.                 if (count > 1){
  32.                     text.append(QString::number(count) + " days ");
  33.                 }
  34.                 else
  35.                 {
  36.                     text.append(QString::number(count) + " day ");
  37.                 }
  38.             }
  39.         }
  40.  
  41.         if(timeoutSeconds > 0){
  42.             unsigned int count = timeoutSeconds / hour;
  43.             timeoutSeconds -= hour * count;
  44.             if (count > 0){
  45.                 if (count > 1){
  46.                     text.append(QString::number(count) + " hours ");
  47.                 }
  48.                 else
  49.                 {
  50.                     text.append(QString::number(count) + " hour ");
  51.                 }
  52.             }
  53.         }
  54.  
  55.         if(timeoutSeconds > 0){
  56.             unsigned int count = timeoutSeconds / minute;
  57.             timeoutSeconds -= minute * count;
  58.             if (count > 0){
  59.                 if (count > 1){
  60.                     text.append(QString::number(count) + " minutes ");
  61.                 }
  62.                 else
  63.                 {
  64.                     text.append(QString::number(count) + " minute ");
  65.                 }
  66.             }
  67.         }
  68.  
  69.         if(timeoutSeconds > 0){
  70.             unsigned int count = timeoutSeconds / second;
  71.             timeoutSeconds -= second * count;
  72.             if (count > 0){
  73.                 if (count > 1){
  74.                     text.append(QString::number(count) + " seconds ");
  75.                 }
  76.                 else
  77.                 {
  78.                     text.append(QString::number(count) + " second ");
  79.                 }
  80.             }
  81.         }
  82.         if(copy > 60){
  83.             text.append("(" + QString::number(copy) + " seconds)");
  84.         }
  85.         return text;
  86.     }
  87.  
  88. }  // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement