summaryrefslogtreecommitdiff
path: root/library/calendar.cpp
Unidiff
Diffstat (limited to 'library/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/calendar.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/library/calendar.cpp b/library/calendar.cpp
new file mode 100644
index 0000000..b9ef585
--- a/dev/null
+++ b/library/calendar.cpp
@@ -0,0 +1,66 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "calendar.h"
21
22#include <qdatetime.h>
23
24QString Calendar::nameOfMonth( int m )
25{
26 QDate d;
27 return d.monthName( m );
28}
29
30QString Calendar::nameOfDay( int d )
31{
32 QDate dt;
33 return dt.dayName( d );
34}
35
36QValueList<Calendar::Day> Calendar::daysOfMonth( int year, int month,
37 bool startWithMonday )
38{
39 QDate temp;
40 temp.setYMD( year, month, 1 );
41 int firstDay = temp.dayOfWeek();
42 int i;
43 QDate prev;
44 QValueList<Day> days;
45
46 if ( startWithMonday )
47 i = 1;
48 else
49 i = 0;
50
51 if ( month > 1 )
52 prev.setYMD( year, month - 1, 1 );
53 else
54 prev.setYMD( year - 1, 12, 1 );
55 for ( ; i < firstDay; i++ ) {
56 days.append( Day( prev.daysInMonth() - ( firstDay - i - 1 ),
57 Day::PrevMonth, FALSE ) );
58 }
59 for ( i = 1; i <= temp.daysInMonth(); i++ )
60 days.append( Day( i, Day::ThisMonth, FALSE ) );
61 i = 0;
62 while ( days.count() < 6 * 7 )
63 days.append( Day( ++i, Day::NextMonth, FALSE ) );
64
65 return days;
66}