File indexing completed on 2024-04-28 16:37:51

0001 #include "kmime_dateformatter.h"
0002 #include <QDebug>
0003 using namespace KMime;
0004 
0005 #ifndef Q_OS_WIN
0006 void initLocale()
0007 {
0008     setenv("LC_ALL", "en_US.utf-8", 1);
0009     setenv("TZ", "UTC", 1);
0010 }
0011 
0012 Q_CONSTRUCTOR_FUNCTION(initLocale)
0013 #endif
0014 
0015 int
0016 main()
0017 {
0018     DateFormatter t;
0019 
0020     auto ntime = QDateTime::currentDateTime();
0021     qDebug() << "Time now:";
0022     qDebug() << "tFancy : \t" << t.dateString(ntime);
0023     t.setFormat(DateFormatter::Localized);
0024     qDebug() << "tLocalized : \t" << t.dateString(ntime);
0025     t.setFormat(DateFormatter::CTime);
0026     qDebug() << "tCTime : \t" << t.dateString(ntime);
0027 
0028     t.setCustomFormat(QStringLiteral("MMMM dddd yyyy Z"));
0029     qDebug() << "tCustom : \t" << t.dateString(ntime);
0030 
0031     ntime = ntime.addSecs(24 * 3600 + 1);
0032     qDebug() << "Time 24 hours and 1 second ago:";
0033     t.setFormat(DateFormatter::Fancy);
0034     qDebug() << "tFancy : \t" << t.dateString(ntime);
0035     t.setFormat(DateFormatter::Localized);
0036     qDebug() << "tLocalized : \t" << t.dateString(ntime);
0037     t.setFormat(DateFormatter::CTime);
0038     qDebug() << "tCTime : \t" << t.dateString(ntime);
0039     t.setCustomFormat(QStringLiteral("MMMM dddd Z yyyy"));
0040     qDebug() << "tCustom : \t" << t.dateString(ntime);
0041 
0042     t.setFormat(DateFormatter::Fancy);
0043     ntime = ntime.addSecs(24 * 3600 * 30 + 59);
0044     qDebug() << "Time 31 days and 1 minute ago:";
0045     qDebug() << "tFancy : \t" << t.dateString(ntime);
0046     t.setFormat(DateFormatter::Localized);
0047     qDebug() << "tLocalized : \t" << t.dateString(ntime);
0048     t.setFormat(DateFormatter::CTime);
0049     qDebug() << "tCTime : \t" << t.dateString(ntime);
0050     t.setCustomFormat(QStringLiteral("MMMM Z dddd yyyy"));
0051     qDebug() << "tCustom : \t" << t.dateString(ntime);
0052 
0053     qDebug() << "Static functions (dates like in the last test):";
0054     qDebug() << "tFancy : \t" << DateFormatter::formatDate(DateFormatter::Fancy, ntime);
0055     qDebug() << "tLocalized : \t" << DateFormatter::formatDate(DateFormatter::Localized, ntime);
0056     qDebug() << "tCTime : \t" << DateFormatter::formatDate(DateFormatter::CTime, ntime);
0057     qDebug() << "tCustom : \t" << DateFormatter::formatDate(DateFormatter::Custom, ntime,
0058              QStringLiteral("Z MMMM dddd yyyy"));
0059     t.setFormat(DateFormatter::Fancy);
0060     qDebug() << "QDateTime taking: (dates as in first test)";
0061     qDebug() << "tFancy : \t" << t.dateString((QDateTime::currentDateTime()));
0062     t.setFormat(DateFormatter::Localized);
0063     qDebug() << "tLocalized : \t" << t.dateString(QDateTime::currentDateTime());
0064     t.setFormat(DateFormatter::CTime);
0065     qDebug() << "tCTime : \t" << t.dateString(QDateTime::currentDateTime());
0066     t.setCustomFormat(QStringLiteral("MMMM d dddd yyyy Z"));
0067     qDebug() << "tCustom : \t" << t.dateString(QDateTime::currentDateTime());
0068 }