-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprettydate.cpp
More file actions
23 lines (21 loc) · 812 Bytes
/
prettydate.cpp
File metadata and controls
23 lines (21 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "prettydate.h"
const QString PrettyDate::JUST_NOW = "Just now ";
const QString PrettyDate::MINUTE_AGO = "Minute ago ";
const QString PrettyDate::MINUTES_AGO = " minutes ago ";
const QString PrettyDate::HOUR_AGO = "Hour ago ";
const QString PrettyDate::HOURS_AGO = " hours ago ";
QString PrettyDate::prettify(QDateTime aDateTime)
{
int secsDiff = aDateTime.secsTo(QDateTime::currentDateTime());
if(secsDiff < 60)
return JUST_NOW;
else if (secsDiff < 120)
return MINUTE_AGO;
else if (secsDiff < 3600)
return QString::number(secsDiff/60) + MINUTES_AGO;
else if (secsDiff < 7200)
return aDateTime.toString("hh:mm:ss");
else if (secsDiff < 86400)
return aDateTime.toString("hh:mm:ss");
return aDateTime.toString("dd/MM/yyyy hh:mm:ss");
}