keepassxc

Форк
0
/
TimeDelta.cpp 
84 строки · 1.7 Кб
1
/*
2
 *  Copyright (C) 2012 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 "TimeDelta.h"
19

20
#include <QDateTime>
21

22
QDateTime operator+(const QDateTime& dateTime, const TimeDelta& delta)
23
{
24
    return dateTime.addSecs(delta.getHours() * 3600)
25
        .addDays(delta.getDays())
26
        .addMonths(delta.getMonths())
27
        .addYears(delta.getYears());
28
}
29

30
TimeDelta TimeDelta::fromHours(int hours)
31
{
32
    return {hours, 0, 0, 0};
33
}
34

35
TimeDelta TimeDelta::fromDays(int days)
36
{
37
    return {0, days, 0, 0};
38
}
39

40
TimeDelta TimeDelta::fromMonths(int months)
41
{
42
    return {0, 0, months, 0};
43
}
44

45
TimeDelta TimeDelta::fromYears(int years)
46
{
47
    return {0, 0, 0, years};
48
}
49

50
TimeDelta::TimeDelta()
51
    : m_hours(0)
52
    , m_days(0)
53
    , m_months(0)
54
    , m_years(0)
55
{
56
}
57

58
TimeDelta::TimeDelta(int hours, int days, int months, int years)
59
    : m_hours(hours)
60
    , m_days(days)
61
    , m_months(months)
62
    , m_years(years)
63
{
64
}
65

66
int TimeDelta::getHours() const
67
{
68
    return m_hours;
69
}
70

71
int TimeDelta::getDays() const
72
{
73
    return m_days;
74
}
75

76
int TimeDelta::getMonths() const
77
{
78
    return m_months;
79
}
80

81
int TimeDelta::getYears() const
82
{
83
    return m_years;
84
}
85

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

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

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

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