645 int unknown[3] = {-1, -1, -1};
652 QRegExp timeRx(
QLatin1String(
"(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)"));
655 while (at < dateString.
length()) {
656 #ifdef PARSEDATESTRINGDEBUG 659 bool isNum =
isNumber(dateString[at]);
665 #ifdef PARSEDATESTRINGDEBUG 666 qDebug() <<
"Month:" << month;
675 int sign = (at >= 0 && dateString[at - 1] ==
'-') ? -1 : 1;
676 zoneOffset = sign *
zoneOffsets[zoneOffset] * 60 * 60;
677 #ifdef PARSEDATESTRINGDEBUG 678 qDebug() <<
"Zone:" << month;
685 && (zoneOffset == -1 || zoneOffset == 0)
686 && (dateString[at] ==
'+' || dateString[at] ==
'-')
689 || dateString[at - 1] ==
',' 691 && (dateString[at - 3] ==
'g')
692 && (dateString[at - 2] ==
'm')
693 && (dateString[at - 1] ==
't')))) {
696 while (end < 5 && dateString.
length() > at+end
697 && dateString[at +
end] >=
'0' && dateString[at +
end] <=
'9')
703 minutes = atoi(dateString.mid(at + 3, 2).constData());
706 hours = atoi(dateString.mid(at + 1, 2).constData());
709 hours = atoi(dateString.mid(at + 1, 1).constData());
716 int sign = dateString[
at] ==
'-' ? -1 : 1;
717 zoneOffset = sign * ((minutes * 60) + (hours * 60 * 60));
718 #ifdef PARSEDATESTRINGDEBUG 719 qDebug() <<
"Zone offset:" << zoneOffset << hours << minutes;
727 if (isNum && time.
isNull()
728 && dateString.length() >= at + 3
729 && (dateString[at + 2] ==
':' || dateString[at + 1] ==
':')) {
742 time =
QTime(h, m, s, ms);
743 #ifdef PARSEDATESTRINGDEBUG 744 qDebug() <<
"Time:" << list << timeRx.matchedLength();
746 at += timeRx.matchedLength();
754 && dateString.length() > at + 3) {
758 year = atoi(dateString.mid(at, 4).constData());
760 #ifdef PARSEDATESTRINGDEBUG 761 qDebug() <<
"Year:" << year;
771 if (dateString.length() > at + 1
774 int x = atoi(dateString.mid(at, length).constData());
775 if (year == -1 && (x > 31 || x == 0)) {
778 if (unknown[0] == -1) unknown[0] = x;
779 else if (unknown[1] == -1) unknown[1] = x;
780 else if (unknown[2] == -1) unknown[2] = x;
783 #ifdef PARSEDATESTRINGDEBUG 784 qDebug() <<
"Saving" << x;
796 int couldBe[3] = { 0, 0, 0 };
797 int unknownCount = 3;
798 for (
int i = 0; i < unknownCount; ++i) {
799 if (unknown[i] == -1) {
808 if (month == -1 && unknown[i] >= 1 && unknown[i] <= 12)
821 for (
int i = 0; i < unknownCount; ++i) {
822 int currentValue = unknown[i];
823 bool findMatchingMonth = couldBe[i] &
ADAY && currentValue >= 29;
824 bool findMatchingDay = couldBe[i] &
AMONTH;
825 if (!findMatchingMonth || !findMatchingDay)
827 for (
int j = 0; j < 3; ++j) {
830 for (
int k = 0; k < 2; ++k) {
831 if (k == 0 && !(findMatchingMonth && (couldBe[j] & AMONTH)))
833 else if (k == 1 && !(findMatchingDay && (couldBe[j] &
ADAY)))
835 int m = currentValue;
839 if (m == -1) m = month;
849 case 4:
case 6:
case 9:
case 11:
854 if (d > 0 && d <= 31)
857 if (k == 0) findMatchingMonth = found;
858 else if (k == 1) findMatchingDay = found;
861 if (findMatchingMonth)
864 couldBe[i] &= ~AMONTH;
869 for (
int i = 0; i < unknownCount; ++i) {
871 for (
int j = 0; j < 3; ++j) {
872 if (couldBe[j] == ADAY && day == -1) {
875 }
else if (couldBe[j] == AMONTH && month == -1) {
878 }
else if (couldBe[j] ==
AYEAR && year == -1) {
885 couldBe[j] &= ~unset;
890 for (
int i = 0; i < unknownCount; ++i) {
891 if (couldBe[i] & AMONTH && month == -1) month = unknown[i];
892 else if (couldBe[i] & ADAY && day == -1) day = unknown[i];
893 else if (couldBe[i] &
AYEAR && year == -1) year = unknown[i];
895 #ifdef PARSEDATESTRINGDEBUG 896 qDebug() <<
"Final set" << year << month << day;
899 if (year == -1 || month == -1 || day == -1) {
900 #ifdef PARSEDATESTRINGDEBUG 901 qDebug() <<
"Parser failure" << year << month << day;
913 QDate date(year + y2k, month, day);
921 date =
QDate(day + y2k, month, year);
925 if (zoneOffset != -1) {
926 dateTime = dateTime.addSecs(zoneOffset);
928 if (!dateTime.isValid())
The QRegExp class provides pattern matching using regular expressions.
bool isNull() const
Returns true if the time is null (i.
#define at(className, varName)
static bool isWhitespace(char c)
The QDate class provides date functions.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool isNumber(char s)
Q_CORE_EXPORT void qDebug(const char *,...)
The QTime class provides clock time functions.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
void qSwap(T &value1, T &value2)
int length() const
Same as size().
const char * constData() const
Returns a pointer to the data stored in the byte array.
The QDateTime class provides date and time functions.
static bool checkStaticArray(int &val, const QByteArray &dateString, int at, const char *array, int size)
static const char months[]
static const KeyPair *const end
static const char zones[]