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