summaryrefslogtreecommitdiffstats
path: root/tdecore/tests/kcalendartest.cpp
blob: 7856c0430d801cdb282d883a5bc7ab597cfb93b5 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Simplest example using two kde calendar systems (gregorian and hijri)
// Carlos Moro <cfmoro@correo.uniovi.es>
// GNU-GPL v.2

#include "kcalendarsystemfactory.h"
#include "kcalendarsystem.h"

#include <tqstringlist.h>

#include <kapplication.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include <kcmdlineargs.h>

class TDELocale;

void test(TQDate & date);

static const char description[] = "KCalendarTest";

static TDECmdLineOptions options[] =
{
  { "help", I18N_NOOP("Prints this help"), 0 },
  { "type hijri|gregorian|jalali|hebrew", I18N_NOOP("Supported calendar types"), 0 },
  { "date <date>", I18N_NOOP("Show day info"), 0 },
};

int main(int argc, char **argv) {

	TQDate date;
	TQString calType, option;
	
        TDEAboutData aboutData( "kcalendartest", "KCalendarTest" ,
                        "0.1", description, TDEAboutData::License_GPL,
                        "(c) 2002, Carlos Moro", 0, 0,
                        "cfmoro@correo.uniovi.es");
  	aboutData.addAuthor("Carlos Moro",0, "cfmoro@correo.uniovi.es");
	

        TDECmdLineArgs::init( argc, argv, &aboutData );
        TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options.

        TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

	TDEApplication app(false, false);

        TQStringList lst = KCalendarSystemFactory::calendarSystems();
	kdDebug() << "Supported calendar types: " << endl;
	for (TQStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
            kdDebug() << *it << endl;
        kdDebug() << endl;

	
        if ( args->isSet("type") )
		calType = args->getOption("type");
	
	
	TDEGlobal::locale()->setCalendar(calType);

  /*
   *  If we like to see some date
   *
   */
      	if ( args->isSet("date") ) {
    		option = args->getOption("date");
                date = TDEGlobal::locale()->readDate(option);
  	} else 
    		date = TQDate::currentDate();

	args->clear(); // Free up some memory.
	
	test(date);

	return 0;	
  
	

}

void test(TQDate & date) {

        kdDebug() << "(TDELocale) readDate" << endl;

        kdDebug() << "Created calendar: " << TDEGlobal::locale()->calendar()->calendarName() << endl;

	kdDebug() << "Day name for first day of week is " << TDEGlobal::locale()->calendar()->weekDayName(1) << endl;
	kdDebug() << "Short month name for second month is " << TDEGlobal::locale()->calendar()->weekDayName(1, true) << endl;

	kdDebug() << "Month name for second month is " << TDEGlobal::locale()->calendar()->monthName(2, TDEGlobal::locale()->calendar()->year(date)) << endl;
	kdDebug() << "Short month name for second month is " << TDEGlobal::locale()->calendar()->monthName(2, TDEGlobal::locale()->calendar()->year(date), true) << endl;
	kdDebug() << "Month name possessive for second month is " << TDEGlobal::locale()->calendar()->monthNamePossessive(2, TDEGlobal::locale()->calendar()->year(date)) << endl;
	kdDebug() << "Short month name possessive for second month is " << TDEGlobal::locale()->calendar()->monthNamePossessive(2, TDEGlobal::locale()->calendar()->year(date), true) << endl;
	kdDebug() << "Month name for fifth month is " << TDEGlobal::locale()->calendar()->monthName(5, TDEGlobal::locale()->calendar()->year(date)) << endl;
	kdDebug() << "Short month name for fifth month is " << TDEGlobal::locale()->calendar()->monthName(5, TDEGlobal::locale()->calendar()->year(date), true) << endl;
	kdDebug() << "Month name possessive for fifth month is " << TDEGlobal::locale()->calendar()->monthNamePossessive(5, TDEGlobal::locale()->calendar()->year(date)) << endl;
	kdDebug() << "Short month name possessive for fifth month is " << TDEGlobal::locale()->calendar()->monthNamePossessive(5, TDEGlobal::locale()->calendar()->year(date), true) << endl;

	kdDebug() << "Day for date " << date.toString() << " is " << TDEGlobal::locale()->calendar()->day(date) << endl;
	kdDebug() << "Month for date " << date.toString() << " is " << TDEGlobal::locale()->calendar()->month(date) << endl;
	kdDebug() << "Year for date " << date.toString() << " is " << TDEGlobal::locale()->calendar()->year(date) << endl;

	kdDebug() << "Day for date " << date.toString() << " as a string is " << TDEGlobal::locale()->calendar()->dayString(date, true) << endl;
	kdDebug() << "Month for date " << date.toString() << " as a string is " << TDEGlobal::locale()->calendar()->monthString(date, true) << endl;
	kdDebug() << "Year for date " << date.toString() << " as a string is " << TDEGlobal::locale()->calendar()->yearString(date, true) << endl;

	kdDebug() << "Day of week for date " << date.toString() << " is number " << TDEGlobal::locale()->calendar()->dayOfWeek(date) << endl;
	kdDebug() << "Week name for date " << date.toString() << " is " << TDEGlobal::locale()->calendar()->weekDayName(date) << endl;
	kdDebug() << "Short week name for date " << date.toString() << " is " << TDEGlobal::locale()->calendar()->weekDayName(date, true) << endl;

	kdDebug() << "Month name for date " << date.toString() <<  " is "  << TDEGlobal::locale()->calendar()->monthName(date) << endl;
	kdDebug() << "Short month name for date " << date.toString() << " is "  << TDEGlobal::locale()->calendar()->monthName(date, true) << endl;
	kdDebug() << "Month name possessive for date " << date.toString() <<  " is "  << TDEGlobal::locale()->calendar()->monthNamePossessive(date) << endl;
	kdDebug() << "Short month name possessive for date " << date.toString() << " is "  << TDEGlobal::locale()->calendar()->monthNamePossessive(date, true) << endl;

 	kdDebug() << "It's week number " << TDEGlobal::locale()->calendar()->weekNumber(date) << endl;


	kdDebug() << "(TDELocale) Formatted date: " << TDEGlobal::locale()->formatDate(date) << endl;
	kdDebug() << "(TDELocale) Short formatted date: " << TDEGlobal::locale()->formatDate(date, true) << endl;

	kdDebug() << "That month have : " << TDEGlobal::locale()->calendar()->daysInMonth(date) << " days" << endl;

	kdDebug() << "That year has " << TDEGlobal::locale()->calendar()->monthsInYear(date) << " months" << endl;
	kdDebug() << "There are " << TDEGlobal::locale()->calendar()->weeksInYear(TDEGlobal::locale()->calendar()->year(date)) << " weeks that year" << endl;
	kdDebug() << "There are " << TDEGlobal::locale()->calendar()->daysInYear(date) << " days that year" << endl;
	
	kdDebug() << "The day of pray is number " << TDEGlobal::locale()->calendar()->weekDayOfPray() << endl;
	
	kdDebug() << "Max valid year supported is " << TDEGlobal::locale()->calendar()->maxValidYear() << endl;
	kdDebug() << "Min valid year supported is " << TDEGlobal::locale()->calendar()->minValidYear() << endl;
	
	kdDebug() << "It's the day number " << TDEGlobal::locale()->calendar()->dayOfYear(date) << " of year" << endl;
	
	kdDebug() << "Add 3 days" << endl;
	date = TDEGlobal::locale()->calendar()->addDays(date, 3);
	kdDebug() << "It's " << TDEGlobal::locale()->formatDate(date) << endl;

	kdDebug() << "Then add 3 months" << endl;
	date = TDEGlobal::locale()->calendar()->addMonths(date, 3);
	kdDebug() << "It's " << TDEGlobal::locale()->formatDate(date) << endl;

	kdDebug() << "And last, add -3 years" << endl;
	date = TDEGlobal::locale()->calendar()->addYears(date, -3);
	kdDebug() << "It's " << TDEGlobal::locale()->formatDate(date) << endl;
	
	kdDebug() << "Is lunar based: " << TDEGlobal::locale()->calendar()->isLunar() << endl;
	kdDebug() << "Is lunisolar based: " << TDEGlobal::locale()->calendar()->isLunisolar() << endl;
	kdDebug() << "Is solar based: " << TDEGlobal::locale()->calendar()->isSolar() << endl;

}