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  hh = tz.leftRef(2).toInt();
52  mm = tz.midRef(2).toInt();
53  }
54 
55  tzsecs = 60 * 60 * hh + 60 * mm;
56  result = result.addSecs(- tzsecs * tzsign);
57  }
58 
59  return result;
60 }
61 
62 const char *Utils::toString(QNetworkAccessManager::Operation operation)
63 {
64  switch(operation) {
65  case QNetworkAccessManager::GetOperation : return "Get";
66  case QNetworkAccessManager::HeadOperation : return "Head";
67  case QNetworkAccessManager::PutOperation : return "Put";
68  case QNetworkAccessManager::PostOperation : return "Post";
69  case QNetworkAccessManager::DeleteOperation : return "Delete";
70  case QNetworkAccessManager::CustomOperation : return "Custom";
71  default: return "unknown";
72  }
73  return "invalid";
74 }
int toInt(bool *ok, int base) const const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
void setTimeSpec(Qt::TimeSpec spec)
int count(const T &value) const const
QStringRef leftRef(int n) const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QDateTime fromString(const QString &string, Qt::DateFormat format)
QStringRef midRef(int position, int n) const const
QDateTime addSecs(qint64 s) const const
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 23:06:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.