1 | /* |
2 | This file is part of KDE. |
3 | |
4 | SPDX-FileCopyrightText: 2010 Intel Corporation |
5 | SPDX-FileContributor: Mateu Batle Sastre <mbatle@collabora.co.uk> |
6 | |
7 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
8 | */ |
9 | |
10 | #include "atticautils.h" |
11 | #include <QStringList> |
12 | #include <QTimeZone> |
13 | |
14 | using namespace Attica; |
15 | |
16 | QDateTime Utils::parseQtDateTimeIso8601(const QString &str) |
17 | { |
18 | QDateTime result; |
19 | QStringList list; |
20 | QString datetime; |
21 | |
22 | int tzsign = 0; |
23 | if (str.indexOf(s: QLatin1String("+" )) != -1) { |
24 | list = str.split(QStringLiteral("+" )); |
25 | datetime = list[0]; |
26 | tzsign = 1; |
27 | } else if (str.indexOf(s: QLatin1String("-" )) != -1) { |
28 | list = str.split(QStringLiteral("-" )); |
29 | datetime = list[0]; |
30 | tzsign = -1; |
31 | } else { |
32 | datetime = str; |
33 | } |
34 | |
35 | // parse date time |
36 | result = QDateTime::fromString(string: datetime, format: Qt::ISODate); |
37 | result.setTimeZone(QTimeZone::utc()); |
38 | |
39 | // parse timezone |
40 | if (list.count() == 2) { |
41 | QString tz = list[1]; |
42 | int hh = 0; |
43 | int mm = 0; |
44 | int tzsecs = 0; |
45 | if (tz.indexOf(c: QLatin1Char(':')) != -1) { |
46 | QStringList tzlist = tz.split(sep: QLatin1Char(':')); |
47 | if (tzlist.count() == 2) { |
48 | hh = tzlist[0].toInt(); |
49 | mm = tzlist[1].toInt(); |
50 | } |
51 | } else { |
52 | QStringView sv(tz); |
53 | hh = sv.left(n: 2).toInt(); |
54 | mm = sv.mid(pos: 2).toInt(); |
55 | } |
56 | |
57 | tzsecs = 60 * 60 * hh + 60 * mm; |
58 | result = result.addSecs(secs: -tzsecs * tzsign); |
59 | } |
60 | |
61 | return result; |
62 | } |
63 | |
64 | const char *Utils::toString(QNetworkAccessManager::Operation operation) |
65 | { |
66 | switch (operation) { |
67 | case QNetworkAccessManager::GetOperation: |
68 | return "Get" ; |
69 | case QNetworkAccessManager::HeadOperation: |
70 | return "Head" ; |
71 | case QNetworkAccessManager::PutOperation: |
72 | return "Put" ; |
73 | case QNetworkAccessManager::PostOperation: |
74 | return "Post" ; |
75 | case QNetworkAccessManager::DeleteOperation: |
76 | return "Delete" ; |
77 | case QNetworkAccessManager::CustomOperation: |
78 | return "Custom" ; |
79 | default: |
80 | return "unknown" ; |
81 | } |
82 | return "invalid" ; |
83 | } |
84 | |