summaryrefslogtreecommitdiffstats
path: root/libkmime/tests/test_dates.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /libkmime/tests/test_dates.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkmime/tests/test_dates.cpp')
-rw-r--r--libkmime/tests/test_dates.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/libkmime/tests/test_dates.cpp b/libkmime/tests/test_dates.cpp
new file mode 100644
index 000000000..f70269282
--- /dev/null
+++ b/libkmime/tests/test_dates.cpp
@@ -0,0 +1,93 @@
+#include <kmime_util.h>
+#include <kmime_header_parsing.h>
+#include <kdebug.h>
+#include <kinstance.h>
+using namespace KMime;
+
+
+int
+main()
+{
+ KInstance app("# ");
+ DateFormatter t;
+
+ time_t ntime = time(0);
+ kdDebug()<<"Time now:"<<endl;
+ kdDebug()<<"\tFancy : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::Localized);
+ kdDebug()<<"\tLocalized : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::CTime);
+ kdDebug()<<"\tCTime : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::Iso);
+ kdDebug()<<"\tIso : \t"<<t.dateString(ntime)<<endl;
+ kdDebug()<<"\trfc2822 : \t"<<t.rfc2822(ntime)<<endl;
+ QString rfcd = t.rfc2822(ntime);
+ Types::DateTime dt;
+ QDateTime qdt;
+ const char *str = rfcd.latin1();
+ if ( HeaderParsing::parseDateTime( str, str + rfcd.length(), dt ) ) {
+ kdDebug()<<"@@@ ntime = "<<(ntime)<<", dt = "<<(dt.time)<<endl;
+ qdt.setTime_t( dt.time );
+ kdDebug()<<"@@@ qq = "<< qdt.toString("ddd, dd MMM yyyy hh:mm:ss") <<endl;
+ kdDebug()<<"@@@ rfc2822 : "<<t.rfc2822(dt.time)<<endl;
+ }
+ QString ddd = "Mon, 05 Aug 2002 01:57:51 -0700";
+ str = ddd.latin1();
+ if ( HeaderParsing::parseDateTime( str, str + ddd.length(), dt ) ) {
+ kdDebug()<<"dt = "<<(dt.time)<<endl;
+ kdDebug()<<"@@@ rfc2822 : "<<t.rfc2822(dt.time)<<endl;
+ }
+
+ t.setCustomFormat("MMMM dddd yyyy Z");
+ kdDebug()<<"\tCustom : \t"<<t.dateString(ntime)<<endl;
+
+ ntime -= (24 * 3600 + 1);
+ kdDebug()<<"Time 24 hours and 1 second ago:"<<endl;
+ t.setFormat( DateFormatter::Fancy );
+ kdDebug()<<"\tFancy : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::Localized);
+ kdDebug()<<"\tLocalized : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::CTime);
+ kdDebug()<<"\tCTime : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::Iso);
+ kdDebug()<<"\tIso : \t"<<t.dateString(ntime)<<endl;
+ kdDebug()<<"\trfc2822 : \t"<<t.rfc2822(ntime)<<endl;
+ t.setCustomFormat("MMMM dddd Z yyyy");
+ kdDebug()<<"\tCustom : \t"<<t.dateString(ntime)<<endl;
+
+ t.setFormat(DateFormatter::Fancy);
+ ntime -= (24*3600 *30 + 59);
+ kdDebug()<<"Time 31 days and 1 minute ago:"<<endl;
+ kdDebug()<<"\tFancy : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::Localized);
+ kdDebug()<<"\tLocalized : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::CTime);
+ kdDebug()<<"\tCTime : \t"<<t.dateString(ntime)<<endl;
+ t.setFormat(DateFormatter::Iso);
+ kdDebug()<<"\tIso : \t"<<t.dateString(ntime)<<endl;
+ kdDebug()<<"\trfc2822 : \t"<<t.rfc2822(ntime)<<endl;
+ t.setCustomFormat("MMMM Z dddd yyyy");
+ kdDebug()<<"\tCustom : \t"<<t.dateString(ntime)<<endl;
+
+
+ kdDebug()<<"Static functions (dates like in the last test):"<<endl;
+ kdDebug()<<"\tFancy : \t"<< DateFormatter::formatDate( DateFormatter::Fancy, ntime) <<endl;
+ kdDebug()<<"\tLocalized : \t"<< DateFormatter::formatDate( DateFormatter::Localized, ntime) <<endl;
+ kdDebug()<<"\tCTime : \t"<< DateFormatter::formatDate( DateFormatter::CTime, ntime ) <<endl;
+ kdDebug()<<"\tIso : \t"<< DateFormatter::formatDate( DateFormatter::Iso, ntime ) <<endl;
+ kdDebug()<<"\trfc2822 : \t"<< DateFormatter::rfc2822FormatDate( ntime ) <<endl;
+ kdDebug()<<"\tCustom : \t"<< DateFormatter::formatDate( DateFormatter::Custom, ntime,
+ "Z MMMM dddd yyyy") <<endl;
+ t.setFormat(DateFormatter::Fancy);
+ kdDebug()<<"QDateTime taking: (dates as in first test)"<<endl;
+ kdDebug()<<"\tFancy : \t"<<t.dateString((QDateTime::currentDateTime()))<<endl;
+ t.setFormat(DateFormatter::Localized);
+ kdDebug()<<"\tLocalized : \t"<<t.dateString(QDateTime::currentDateTime())<<endl;
+ t.setFormat(DateFormatter::CTime);
+ kdDebug()<<"\tCTime : \t"<<t.dateString(QDateTime::currentDateTime())<<endl;
+ t.setFormat(DateFormatter::Iso);
+ kdDebug()<<"\tIso : \t"<<t.dateString(QDateTime::currentDateTime())<<endl;
+ t.setCustomFormat("MMMM d dddd yyyy Z");
+ kdDebug()<<"\tCustom : \t"<<t.dateString(QDateTime::currentDateTime())<<endl;
+
+}