@brief Date/time string parsing *----------------------------------------------------------------------------*/
| 909 | /** @brief Date/time string parsing |
| 910 | *----------------------------------------------------------------------------*/ |
| 911 | QString ParseObject::parseDate(const QString &dateString, const QString &urlString) |
| 912 | { |
| 913 | QDateTime dt; |
| 914 | QString temp; |
| 915 | QString timeZone; |
| 916 | |
| 917 | if (dateString.isEmpty()) return QString(); |
| 918 | |
| 919 | QDateTime dtLocalTime = QDateTime::currentDateTime(); |
| 920 | QDateTime dtUTC = QDateTime(dtLocalTime.date(), dtLocalTime.time(), Qt::UTC); |
| 921 | int nTimeShift = dtLocalTime.secsTo(dtUTC)/3600; |
| 922 | |
| 923 | QString ds = dateString.simplified(); |
| 924 | QLocale locale(QLocale::C); |
| 925 | |
| 926 | if (ds.indexOf(',') != -1) { |
| 927 | ds = ds.remove(0, ds.indexOf(',')+1).simplified(); |
| 928 | } |
| 929 | |
| 930 | for (int i = 0; i < 2; i++, locale = QLocale::system()) { |
| 931 | temp = ds.left(23); |
| 932 | timeZone = ds.mid(temp.length(), 3); |
| 933 | if (timeZone.isEmpty()) timeZone = QString::number(nTimeShift); |
| 934 | dt = locale.toDateTime(temp, "yyyy-MM-ddTHH:mm:ss.z"); |
| 935 | if (dt.isValid()) return locale.toString(dt.addSecs(timeZone.toInt() * -3600), "yyyy-MM-ddTHH:mm:ss"); |
| 936 | |
| 937 | temp = ds.left(19); |
| 938 | timeZone = ds.mid(temp.length(), 3); |
| 939 | if (timeZone.isEmpty()) timeZone = QString::number(nTimeShift); |
| 940 | dt = locale.toDateTime(temp, "yyyy-MM-ddTHH:mm:ss"); |
| 941 | if (dt.isValid()) return locale.toString(dt.addSecs(timeZone.toInt() * -3600), "yyyy-MM-ddTHH:mm:ss"); |
| 942 | |
| 943 | temp = ds.left(23); |
| 944 | timeZone = ds.mid(temp.length()+1, 3); |
| 945 | if (timeZone.isEmpty()) timeZone = QString::number(nTimeShift); |
| 946 | dt = locale.toDateTime(temp, "yyyy-MM-dd HH:mm:ss.z"); |
| 947 | if (dt.isValid()) return locale.toString(dt.addSecs(timeZone.toInt() * -3600), "yyyy-MM-ddTHH:mm:ss"); |
| 948 | |
| 949 | temp = ds.left(19); |
| 950 | timeZone = ds.mid(temp.length()+1, 3); |
| 951 | if (timeZone.isEmpty()) timeZone = QString::number(nTimeShift); |
| 952 | dt = locale.toDateTime(temp, "yyyy-MM-dd HH:mm:ss"); |
| 953 | if (dt.isValid()) return locale.toString(dt.addSecs(timeZone.toInt() * -3600), "yyyy-MM-ddTHH:mm:ss"); |
| 954 | |
| 955 | temp = ds.left(20); |
| 956 | timeZone = ds.mid(temp.length()+1, 3); |
| 957 | if (timeZone.contains("EDT")) |
| 958 | timeZone="-4"; |
| 959 | if (timeZone.isEmpty()) timeZone = QString::number(nTimeShift); |
| 960 | dt = locale.toDateTime(temp, "dd MMM yyyy HH:mm:ss"); |
| 961 | if (dt.isValid()) return locale.toString(dt.addSecs(timeZone.toInt() * -3600), "yyyy-MM-ddTHH:mm:ss"); |
| 962 | |
| 963 | temp = ds.left(19); |
| 964 | timeZone = ds.mid(temp.length()+1, 3); |
| 965 | if (timeZone.isEmpty()) timeZone = QString::number(nTimeShift); |
| 966 | dt = locale.toDateTime(temp, "d MMM yyyy HH:mm:ss"); |
| 967 | if (dt.isValid()) return locale.toString(dt.addSecs(timeZone.toInt() * -3600), "yyyy-MM-ddTHH:mm:ss"); |
| 968 |