keepassxc

Форк
0
/
TimeInfo.cpp 
140 строк · 3.4 Кб
1
/*
2
 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "TimeInfo.h"
19

20
TimeInfo::TimeInfo()
21
    : m_expires(false)
22
    , m_usageCount(0)
23
{
24
    QDateTime now = Clock::currentDateTimeUtc();
25
    m_lastModificationTime = now;
26
    m_creationTime = now;
27
    m_lastAccessTime = now;
28
    m_expiryTime = now;
29
    m_locationChanged = now;
30
}
31

32
QDateTime TimeInfo::lastModificationTime() const
33
{
34
    return m_lastModificationTime;
35
}
36

37
QDateTime TimeInfo::creationTime() const
38
{
39
    return m_creationTime;
40
}
41

42
QDateTime TimeInfo::lastAccessTime() const
43
{
44
    return m_lastAccessTime;
45
}
46

47
QDateTime TimeInfo::expiryTime() const
48
{
49
    return m_expiryTime;
50
}
51

52
bool TimeInfo::expires() const
53
{
54
    return m_expires;
55
}
56

57
int TimeInfo::usageCount() const
58
{
59
    return m_usageCount;
60
}
61

62
QDateTime TimeInfo::locationChanged() const
63
{
64
    return m_locationChanged;
65
}
66

67
void TimeInfo::setLastModificationTime(const QDateTime& dateTime)
68
{
69
    Q_ASSERT(dateTime.timeSpec() == Qt::UTC);
70
    m_lastModificationTime = dateTime;
71
}
72

73
void TimeInfo::setCreationTime(const QDateTime& dateTime)
74
{
75
    Q_ASSERT(dateTime.timeSpec() == Qt::UTC);
76
    m_creationTime = dateTime;
77
}
78

79
void TimeInfo::setLastAccessTime(const QDateTime& dateTime)
80
{
81
    Q_ASSERT(dateTime.timeSpec() == Qt::UTC);
82
    m_lastAccessTime = dateTime;
83
}
84

85
void TimeInfo::setExpiryTime(const QDateTime& dateTime)
86
{
87
    Q_ASSERT(dateTime.timeSpec() == Qt::UTC);
88
    m_expiryTime = dateTime;
89
}
90

91
void TimeInfo::setExpires(bool expires)
92
{
93
    m_expires = expires;
94
}
95

96
void TimeInfo::setUsageCount(int count)
97
{
98
    m_usageCount = count;
99
}
100

101
void TimeInfo::setLocationChanged(const QDateTime& dateTime)
102
{
103
    Q_ASSERT(dateTime.timeSpec() == Qt::UTC);
104
    m_locationChanged = dateTime;
105
}
106

107
bool TimeInfo::operator==(const TimeInfo& other) const
108
{
109
    return equals(other, CompareItemDefault);
110
}
111

112
bool TimeInfo::operator!=(const TimeInfo& other) const
113
{
114
    return !this->operator==(other);
115
}
116

117
bool TimeInfo::equals(const TimeInfo& other, CompareItemOptions options) const
118
{
119
    // clang-format off
120
    if (::compare(m_lastModificationTime, other.m_lastModificationTime, options) != 0) {
121
        return false;
122
    }
123
    if (::compare(m_creationTime, other.m_creationTime, options) != 0) {
124
        return false;
125
    }
126
    if (::compare(!options.testFlag(CompareItemIgnoreStatistics), m_lastAccessTime, other.m_lastAccessTime, options) != 0) {
127
        return false;
128
    }
129
    if (::compare(m_expires, m_expiryTime, other.m_expires, other.expiryTime(), options) != 0) {
130
        return false;
131
    }
132
    if (::compare(!options.testFlag(CompareItemIgnoreStatistics), m_usageCount, other.m_usageCount, options) != 0) {
133
        return false;
134
    }
135
    if (::compare(!options.testFlag(CompareItemIgnoreLocation), m_locationChanged, other.m_locationChanged, options) != 0) {
136
        return false;
137
    }
138
    return true;
139
    // clang-format on
140
}
141

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.