Attica

atticautils.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2010 Intel Corporation
5  SPDX-FileContributor: Mateu Batle Sastre <[email protected]>
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 
13 using namespace Attica;
14 
15 QDateTime Utils::parseQtDateTimeIso8601(const QString &str)
16 {
17  QDateTime result;
19  QString datetime;
20 
21  int tzsign = 0;
22  if (str.indexOf(QLatin1String("+")) != -1) {
23  list = str.split(QStringLiteral("+"));
24  datetime = list[0];
25  tzsign = 1;
26  } else if (str.indexOf(QLatin1String("-")) != -1) {
27  list = str.split(QStringLiteral("-"));
28  datetime = list[0];
29  tzsign = -1;
30  } else {
31  datetime = str;
32  }
33 
34  // parse date time
35  result = QDateTime::fromString(datetime, Qt::ISODate);
36  result.setTimeSpec(Qt::UTC);
37 
38  // parse timezone
39  if (list.count() == 2) {
40  QString tz = list[1];
41  int hh = 0;
42  int mm = 0;
43  int tzsecs = 0;
44  if (tz.indexOf(QLatin1Char(':')) != -1) {
45  QStringList tzlist = tz.split(QLatin1Char(':'));
46  if (tzlist.count() == 2) {
47  hh = tzlist[0].toInt();
48  mm = tzlist[1].toInt();
49  }
50  } else {
51 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
52  QStringView sv(tz);
53  hh = sv.left(2).toInt();
54  mm = sv.mid(2).toInt();
55 #else
56  hh = tz.leftRef(2).toInt();
57  mm = tz.midRef(2).toInt();
58 #endif
59  }
60 
61  tzsecs = 60 * 60 * hh + 60 * mm;
62  result = result.addSecs(-tzsecs * tzsign);
63  }
64 
65  return result;
66 }
67 
68 const char *Utils::toString(QNetworkAccessManager::Operation operation)
69 {
70  switch (operation) {
72  return "Get";
74  return "Head";
76  return "Put";
78  return "Post";
80  return "Delete";
82  return "Custom";
83  default:
84  return "unknown";
85  }
86  return "invalid";
87 }
QDateTime addSecs(qint64 s) const const
int toInt(bool *ok, int base) const const
QStringRef midRef(int position, int n) const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
int count(const T &value) const const
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
void setTimeSpec(Qt::TimeSpec spec)
QDateTime fromString(const QString &string, Qt::DateFormat format)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
The Attica namespace,.
QStringRef leftRef(int n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 04:08:16 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.