This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathznote.cpp
70 lines (68 loc) · 2.13 KB
/
znote.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "znote.h"
ZNote::ZNote(const bool isAttached)
: attachment(isAttached)
{
updateTime = createTime = QDateTime::currentDateTime();
}
ZNote::ZNote(const QDateTime& key)
: updateTime(key)
{
}
ZNote::ZNote(const QDateTime& create, const QDateTime& upd, const QString& html, const QString& abstract, const bool isAttached)
: createTime(create)
, updateTime(upd)
, html(html)
, abstract(abstract)
, attachment(isAttached)
{
}
ZNote::ZNote(const ZNote& other)
: createTime(other.createTime)
, updateTime(other.updateTime)
, html(other.html)
, abstract(other.abstract)
, attachment(other.attachment)
{
}
ZNote::ZNote(const QJsonObject& obj)
: attachment(true)
{
// qDebug()<<obj;
//if (obj.contains("createTime") && obj.contains("updateTime") && obj.contains("html") && obj.contains("abstract")) {
createTime = QDateTime::fromString(obj["createTime"].toString(), Qt::ISODate);
updateTime = QDateTime::fromString(obj["updateTime"].toString(), Qt::ISODateWithMs);
html = obj["html"].toString();
abstract = obj["abstract"].toString();
//}
}
QJsonObject ZNote::jsonObject() const
{
QJsonObject obj;
obj["createTime"] = createTime.toString(Qt::ISODate);
obj["updateTime"] = updateTime.toString(Qt::ISODateWithMs);
obj["abstract"] = abstract;
obj["html"] = html;
return obj;
}
QString ZNote::humanDateTime(const QDateTime& from)
{
auto cur = QDateTime::currentDateTime();
if (from.daysTo(cur) == 0) {
if (from.secsTo(cur) <= 60)
return QObject::tr("刚刚");
else if (from.secsTo(cur) <= 3600)
return QObject::tr("%n minute(s) ago", "", int(from.secsTo(cur) / 60));
else if (from.secsTo(cur) <= 3600 * 3)
return QObject::tr("%n hour(s) ago", "", int(from.secsTo(cur) / 3600));
else
return from.toString("hh:mm:ss");
} else if (from.daysTo(cur) <= 3)
return QObject::tr("%n day(s) ago", "", int(from.daysTo(cur)));
else
return from.toString("yyyy-MM-dd hh:mm");
}
QDebug operator<<(QDebug o, const ZNote& z)
{
o << z.jsonObject() << endl;
return o;
}