Advertisement
Lajamerr_Mittesdine

Timeout message length

Jul 11th, 2018
545
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 weekSec = 604800;
  6.         int weeks = 0;
  7.         time_t seconds(timeoutSeconds);
  8.         QString text;
  9.  
  10.         if (seconds < weekSec) {
  11.             weeks = 0;
  12.         }
  13.         else {
  14.             weeks = seconds/weekSec;
  15.         }
  16.         seconds = seconds- (weeks*weekSec);
  17.         tm *p = gmtime(&seconds);
  18.  
  19.         if(weeks > 0){
  20.             text.append(QString::number(weeks));
  21.             if(weeks > 1){
  22.                 text.append(" weeks ");
  23.             }
  24.             else{
  25.                 text.append(" week ");
  26.             }
  27.         }
  28.  
  29.         if(p->tm_yday > 0){
  30.             text.append(QString::number(p->tm_yday));
  31.             if(p->tm_yday > 1){
  32.                 text.append(" days ");
  33.             }
  34.             else{
  35.                 text.append(" day ");
  36.             }
  37.         }
  38.  
  39.         if(p->tm_hour > 0){
  40.             text.append(QString::number(p->tm_hour));
  41.             if(p->tm_hour > 1){
  42.                 text.append(" hours ");
  43.             }
  44.             else{
  45.                 text.append(" hour ");
  46.             }
  47.         }
  48.  
  49.         if(p->tm_min > 0){
  50.             text.append(QString::number(p->tm_min));
  51.             if(p->tm_min > 1){
  52.                 text.append(" minutes ");
  53.             }
  54.             else{
  55.                 text.append(" minute ");
  56.             }
  57.         }
  58.  
  59.         if(p->tm_sec > 0){
  60.             text.append(QString::number(p->tm_sec));
  61.             if(p->tm_sec > 1){
  62.                 text.append(" seconds ");
  63.             }
  64.             else{
  65.                 text.append(" second ");
  66.             }
  67.         }
  68.  
  69.         if(timeoutSeconds > 60){
  70.             text.append("(" + QString::number(timeoutSeconds) + " seconds)");
  71.         }
  72.  
  73.         return text;
  74.     }
  75.  
  76. }  // namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement