File indexing completed on 2024-12-08 03:37:09
0001 /* 0002 This file is part of KDE. 0003 0004 SPDX-FileCopyrightText: 2010 Intel Corporation 0005 SPDX-FileContributor: Mateu Batle Sastre <mbatle@collabora.co.uk> 0006 0007 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0008 */ 0009 0010 #include "atticautils.h" 0011 #include <QStringList> 0012 #include <QTimeZone> 0013 0014 using namespace Attica; 0015 0016 QDateTime Utils::parseQtDateTimeIso8601(const QString &str) 0017 { 0018 QDateTime result; 0019 QStringList list; 0020 QString datetime; 0021 0022 int tzsign = 0; 0023 if (str.indexOf(QLatin1String("+")) != -1) { 0024 list = str.split(QStringLiteral("+")); 0025 datetime = list[0]; 0026 tzsign = 1; 0027 } else if (str.indexOf(QLatin1String("-")) != -1) { 0028 list = str.split(QStringLiteral("-")); 0029 datetime = list[0]; 0030 tzsign = -1; 0031 } else { 0032 datetime = str; 0033 } 0034 0035 // parse date time 0036 result = QDateTime::fromString(datetime, Qt::ISODate); 0037 result.setTimeZone(QTimeZone::utc()); 0038 0039 // parse timezone 0040 if (list.count() == 2) { 0041 QString tz = list[1]; 0042 int hh = 0; 0043 int mm = 0; 0044 int tzsecs = 0; 0045 if (tz.indexOf(QLatin1Char(':')) != -1) { 0046 QStringList tzlist = tz.split(QLatin1Char(':')); 0047 if (tzlist.count() == 2) { 0048 hh = tzlist[0].toInt(); 0049 mm = tzlist[1].toInt(); 0050 } 0051 } else { 0052 QStringView sv(tz); 0053 hh = sv.left(2).toInt(); 0054 mm = sv.mid(2).toInt(); 0055 } 0056 0057 tzsecs = 60 * 60 * hh + 60 * mm; 0058 result = result.addSecs(-tzsecs * tzsign); 0059 } 0060 0061 return result; 0062 } 0063 0064 const char *Utils::toString(QNetworkAccessManager::Operation operation) 0065 { 0066 switch (operation) { 0067 case QNetworkAccessManager::GetOperation: 0068 return "Get"; 0069 case QNetworkAccessManager::HeadOperation: 0070 return "Head"; 0071 case QNetworkAccessManager::PutOperation: 0072 return "Put"; 0073 case QNetworkAccessManager::PostOperation: 0074 return "Post"; 0075 case QNetworkAccessManager::DeleteOperation: 0076 return "Delete"; 0077 case QNetworkAccessManager::CustomOperation: 0078 return "Custom"; 0079 default: 0080 return "unknown"; 0081 } 0082 return "invalid"; 0083 }