Attica

atticautils.cpp
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
14using namespace Attica;
15
16QDateTime Utils::parseQtDateTimeIso8601(const QString &str)
17{
18 QDateTime result;
20 QString datetime;
21
22 int tzsign = 0;
23 if (str.indexOf(QLatin1String("+")) != -1) {
24 list = str.split(QStringLiteral("+"));
25 datetime = list[0];
26 tzsign = 1;
27 } else if (str.indexOf(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(datetime, Qt::ISODate);
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(QLatin1Char(':')) != -1) {
46 QStringList tzlist = tz.split(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(2).toInt();
54 mm = sv.mid(2).toInt();
55 }
56
57 tzsecs = 60 * 60 * hh + 60 * mm;
58 result = result.addSecs(-tzsecs * tzsign);
59 }
60
61 return result;
62}
63
64const char *Utils::toString(QNetworkAccessManager::Operation operation)
65{
66 switch (operation) {
68 return "Get";
70 return "Head";
72 return "Put";
74 return "Post";
76 return "Delete";
78 return "Custom";
79 default:
80 return "unknown";
81 }
82 return "invalid";
83}
The Attica namespace,.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QDateTime addSecs(qint64 s) const const
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
void setTimeZone(const QTimeZone &toZone)
qsizetype count() const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QTimeZone utc()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:33 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.