#include <kmime_util.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;
  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;
  
}
