fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kde3support / tests / krfcdatetest.cpp
blob9f91a6c2580335fad6d8d97505e7545f6a097c73
1 #include "qtest_kde.h"
2 #include "krfcdatetest.h"
3 #include "krfcdatetest.moc"
5 QTEST_KDEMAIN(KRFCDateTest, NoGUI)
7 #include "k3rfcdate.h"
9 void KRFCDateTest::test()
11 // valid RFC dates
13 // From http://www.w3.org/TR/NOTE-datetime
14 time_t ref = K3RFCDate::parseDateISO8601("1994-11-05T13:15:30Z");
16 QCOMPARE(K3RFCDate::parseDateISO8601("1994-11-05T08:15:30-05:00"), ref);
17 QCOMPARE(K3RFCDate::parseDateISO8601("1994-11-05T18:15:30+05:00"), ref);
18 QCOMPARE(K3RFCDate::parseDate("Thu Nov 5 1994 18:15:30 GMT+0500"), ref);
19 QCOMPARE(K3RFCDate::parseDate("Thu Nov 5 1994 18:15:30 GMT+05:00"), ref);
20 QCOMPARE(K3RFCDate::parseDate("Wednesday, 05-Nov-94 13:15:30 GMT"), ref);
21 QCOMPARE(K3RFCDate::parseDate("Wed, 05-Nov-1994 13:15:30 GMT"), ref);
22 QCOMPARE(K3RFCDate::parseDate("Wed, 05-November-1994 13:15:30 GMT"), ref);
24 // invalid dates
26 ref = 0;
28 // pass RFC date to ISO parser
29 QCOMPARE(K3RFCDate::parseDateISO8601("Thu, 01 Jan 2004 19:48:21 GMT"), ref);
30 // pass ISO date to RFC parser
31 QCOMPARE(K3RFCDate::parseDate("1994-01-01T12:00:00"), ref);
33 // empty/null strings
34 QCOMPARE(K3RFCDate::parseDateISO8601(QString()), ref);
35 QCOMPARE(K3RFCDate::parseDateISO8601(""), ref);
36 QCOMPARE(K3RFCDate::parseDate(QString()), ref);
37 QCOMPARE(K3RFCDate::parseDate(""), ref);
40 // valid ISO dates
42 ref = K3RFCDate::parseDateISO8601("1994-01-01T12:00:00");
44 QCOMPARE(K3RFCDate::parseDateISO8601("1994"), ref);
45 QCOMPARE(K3RFCDate::parseDateISO8601("1994-01"), ref);
46 QCOMPARE(K3RFCDate::parseDateISO8601("1994-01-01"), ref);
50 void KRFCDateTest::testRFC2822()
52 QDateTime local = QDateTime::currentDateTime();
53 QDateTime utc = local.toUTC();
55 QCOMPARE(QString(K3RFCDate::rfc2822DateString(utc.toTime_t(), 0)),
56 utc.toString("ddd, dd MMM yyyy hh:mm:ss +0000"));
58 int offset = K3RFCDate::localUTCOffset();
59 int z = qAbs(offset);
60 QCOMPARE(QString(K3RFCDate::rfc2822DateString(local.toTime_t(), offset)),
61 local.toString("ddd, dd MMM yyyy hh:mm:ss %1%2%3")
62 .arg(offset < 0? '-' : '+')
63 .arg(int(z/60%24), 2, 10, QLatin1Char('0'))
64 .arg(int(z%60), 2, 10, QLatin1Char('0')));
66 QCOMPARE(K3RFCDate::rfc2822DateString(local.toTime_t(), offset),
67 K3RFCDate::rfc2822DateString(local.toTime_t()));