summaryrefslogtreecommitdiffstats
path: root/libkmime/tests/test_dates.cpp
blob: e3a40f812581f75acaade0fdbd8d3cc97a287953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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;
  TQString rfcd = t.rfc2822(ntime);
  Types::DateTime dt;
  TQDateTime 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;
  }
  TQString 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()<<"TQDateTime taking: (dates as in first test)"<<endl;
  kdDebug()<<"\tFancy : \t"<<t.dateString((TQDateTime::tqcurrentDateTime()))<<endl;
  t.setFormat(DateFormatter::Localized);
  kdDebug()<<"\tLocalized : \t"<<t.dateString(TQDateTime::tqcurrentDateTime())<<endl;
  t.setFormat(DateFormatter::CTime);
  kdDebug()<<"\tCTime : \t"<<t.dateString(TQDateTime::tqcurrentDateTime())<<endl;
  t.setFormat(DateFormatter::Iso);
  kdDebug()<<"\tIso   : \t"<<t.dateString(TQDateTime::tqcurrentDateTime())<<endl;
  t.setCustomFormat("MMMM d dddd yyyy Z");
  kdDebug()<<"\tCustom : \t"<<t.dateString(TQDateTime::tqcurrentDateTime())<<endl;

}