summaryrefslogtreecommitdiff
path: root/library/timestring.cpp
Unidiff
Diffstat (limited to 'library/timestring.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/timestring.cpp51
1 files changed, 28 insertions, 23 deletions
diff --git a/library/timestring.cpp b/library/timestring.cpp
index d5d78ae..4c6fa72 100644
--- a/library/timestring.cpp
+++ b/library/timestring.cpp
@@ -1,16 +1,16 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
@@ -108,86 +108,82 @@ QString DateFormat::toWordString() const
108 if (i < 2) 108 if (i < 2)
109 buf += ", "; 109 buf += ", ";
110 break; 110 break;
111 } 111 }
112 } 112 }
113 return buf; 113 return buf;
114} 114}
115 115
116QString DateFormat::numberDate(const QDate &d, int v) const 116QString DateFormat::numberDate(const QDate &d, int v) const
117{ 117{
118 QString buf = ""; 118 QString buf = "";
119 119
120 int pad = 0; 120 int pad = 2;
121 if (v & padNumber)
122 pad = 2;
123 121
124 // for each part of the order 122 // for each part of the order
125 for (int i = 0; i < 3; i++) { 123 for (int i = 0; i < 3; i++) {
126 // switch on the relavent 3 bits. 124 // switch on the relavent 3 bits.
127 switch((_shortOrder >> (i * 3)) & 0x0007) { 125 switch((_shortOrder >> (i * 3)) & 0x0007) {
128 case 0x0001: 126 case 0x0001:
129 buf += QString("%1").arg(d.day(), pad); 127 if (pad==2) buf += QString().sprintf("%02d",d.day());
128 else buf += QString().sprintf("%d",d.day());
130 break; 129 break;
131 case 0x0002: 130 case 0x0002:
132 buf += QString("%1").arg(d.month(), pad); 131 if (i==0) { // no padding with only MM/DD/YY format
132 pad=0;
133 }
134 if (pad==2) buf += QString().sprintf("%02d",d.month());
135 else buf += QString().sprintf("%d",d.month());
133 break; 136 break;
134 case 0x0004: 137 case 0x0004:
135 { 138 {
136 int year = d.year(); 139 int year = d.year();
137 if (!(v & longNumber)) 140 if (!(v & longNumber))
138 year = year % 100; 141 year = year % 100;
139 142 buf += QString().sprintf("%02d",year);
140 if (year < 10)
141 buf += "0";
142
143 buf += QString::number(year);
144
145 } 143 }
146 break; 144 break;
147 } 145 }
148 if (i < 2) 146 if (i < 2)
149 buf = _shortSeparator; 147 buf += _shortSeparator;
150 } 148 }
151 return buf; 149 return buf;
152} 150}
153 151
154QString DateFormat::wordDate(const QDate &d, int v) const 152QString DateFormat::wordDate(const QDate &d, int v) const
155{ 153{
156 QString buf = ""; 154 QString buf = "";
157 // for each part of the order 155 // for each part of the order
158 if (v & showWeekDay) { 156 if (v & showWeekDay) {
159 QString weekDay = d.dayName(d.dayOfWeek()); 157 QString weekDay = d.dayName(d.dayOfWeek());
160 if (!(v & longWord)) { 158 if (!(v & longWord)) {
161 weekDay = weekDay.left(3); 159 weekDay = weekDay.left(3);
162 } 160 }
163 buf += weekDay; 161 buf += weekDay;
164 if (_longOrder & 0x0007 == 0x0002) 162 if ((_longOrder & 0x0007) == 0x0002)
165 buf += ' '; 163 buf += ' ';
166 else 164 else
167 buf += ", "; 165 buf += ", ";
168 } 166 }
169 167
170 int pad = 0;
171 if (v & padNumber)
172 pad = 2;
173
174 for (int i = 0; i < 3; i++) { 168 for (int i = 0; i < 3; i++) {
175 // switch on the relavent 3 bits. 169 // switch on the relavent 3 bits.
176 switch((_longOrder >> (i * 3)) & 0x0007) { 170 switch((_longOrder >> (i * 3)) & 0x0007) {
177 case 0x0001: 171 case 0x0001:
178 buf += QString("%1").arg(d.day(), pad); 172 if (i==1) {
179 if (i < 2) { 173 buf += QString().sprintf("%02d, ",d.day());
180 if ((_shortOrder << ((i+1) * 3)) & 0x0007) 174 } else {
181 buf += ", "; 175 buf += QString().sprintf("%2d",d.day());
176 if (separator()=='.') // 2002/1/11
177 buf += ". ";
182 else 178 else
183 buf += " "; 179 buf += " ";
184 } 180 }
185 break; 181 break;
186 case 0x0002: 182 case 0x0002:
187 { 183 {
188 QString monthName = d.monthName(d.month()); 184 QString monthName = d.monthName(d.month());
189 if (!(v & longWord)) { 185 if (!(v & longWord)) {
190 monthName = monthName.left(3); 186 monthName = monthName.left(3);
191 } 187 }
192 buf += monthName; 188 buf += monthName;
193 } 189 }
@@ -348,13 +344,22 @@ QString TimeString::dateString( const QDateTime &t, bool ampm )
348} 344}
349 345
350QString TimeString::timeString( const QTime &t, bool ampm) 346QString TimeString::timeString( const QTime &t, bool ampm)
351{ 347{
352 return timeString(t,ampm,FALSE); 348 return timeString(t,ampm,FALSE);
353} 349}
354 350
355QString TimeString::shortTime( bool ampm ) 351QString TimeString::shortTime( bool ampm )
356{ 352{
357 return shortTime(ampm,FALSE); 353 return shortTime(ampm,FALSE);
358} 354}
359 355
356QString TimeString::numberDateString( const QDate &d, DateFormat dtf )
357{
358 return dtf.numberDate(d);
359}
360QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf )
361{
362 return dtf.numberDate(d,DateFormat::longNumber);
363}
364
360#include "timestring.moc" 365#include "timestring.moc"