author | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
commit | 6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 (patch) (side-by-side diff) | |
tree | 6ebc93c6432f4ed9d00ef1448b6a047ef522a79a /library/timestring.cpp | |
parent | d10cddb3c9ce75bc90b14add14bc133737fe35aa (diff) | |
download | opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.zip opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.gz opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.bz2 |
Qtopia1-6 merge
still to test
bic changes to be resolved
more changes to be made?
-rw-r--r-- | library/timestring.cpp | 51 |
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,36 +1,36 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "timestring.h" #include <qobject.h> #include "qpeapplication.h" //for qApp #include "config.h" class TimeStringFormatKeeper : public QObject { Q_OBJECT public: static DateFormat currentFormat() { if ( !self ) self = new TimeStringFormatKeeper; return self->format; } @@ -88,126 +88,122 @@ QString DateFormat::toWordString() const // for each part of the order for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. switch((_longOrder >> (i * 3)) & 0x0007) { case 0x0001: buf += QObject::tr( "day" ); if (i < 2) { if ((_shortOrder << ((i+1) * 3)) & 0x0007) buf += ", "; else buf += " "; } break; case 0x0002: buf += QObject::tr( "month" ); if (i < 2) buf += " "; break; case 0x0004: buf += QObject::tr( "year" ); if (i < 2) buf += ", "; break; } } return buf; } QString DateFormat::numberDate(const QDate &d, int v) const { QString buf = ""; - int pad = 0; - if (v & padNumber) - pad = 2; + int pad = 2; // for each part of the order for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. switch((_shortOrder >> (i * 3)) & 0x0007) { case 0x0001: - buf += QString("%1").arg(d.day(), pad); + if (pad==2) buf += QString().sprintf("%02d",d.day()); + else buf += QString().sprintf("%d",d.day()); break; case 0x0002: - buf += QString("%1").arg(d.month(), pad); + if (i==0) { // no padding with only MM/DD/YY format + pad=0; + } + if (pad==2) buf += QString().sprintf("%02d",d.month()); + else buf += QString().sprintf("%d",d.month()); break; case 0x0004: { int year = d.year(); if (!(v & longNumber)) year = year % 100; - - if (year < 10) - buf += "0"; - - buf += QString::number(year); - + buf += QString().sprintf("%02d",year); } break; } if (i < 2) - buf = _shortSeparator; + buf += _shortSeparator; } return buf; } QString DateFormat::wordDate(const QDate &d, int v) const { QString buf = ""; // for each part of the order if (v & showWeekDay) { QString weekDay = d.dayName(d.dayOfWeek()); if (!(v & longWord)) { weekDay = weekDay.left(3); } buf += weekDay; - if (_longOrder & 0x0007 == 0x0002) + if ((_longOrder & 0x0007) == 0x0002) buf += ' '; else buf += ", "; } - int pad = 0; - if (v & padNumber) - pad = 2; - for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. switch((_longOrder >> (i * 3)) & 0x0007) { case 0x0001: - buf += QString("%1").arg(d.day(), pad); - if (i < 2) { - if ((_shortOrder << ((i+1) * 3)) & 0x0007) - buf += ", "; + if (i==1) { + buf += QString().sprintf("%02d, ",d.day()); + } else { + buf += QString().sprintf("%2d",d.day()); + if (separator()=='.') // 2002/1/11 + buf += ". "; else buf += " "; } break; case 0x0002: { QString monthName = d.monthName(d.month()); if (!(v & longWord)) { monthName = monthName.left(3); } buf += monthName; } if (i < 2) buf += " "; break; case 0x0004: { int year = d.year(); if (!(v & longNumber)) year = year % 100; if (year < 10) buf += "0"; buf += QString::number(year); } if (i < 2) buf += ", "; break; } } return buf; @@ -328,33 +324,42 @@ QString TimeString::shortTime( bool ampm, bool seconds ) static const char* const day[] = { QT_TRANSLATE_NOOP( "QObject", "Mon" ), QT_TRANSLATE_NOOP( "QObject", "Tue" ), QT_TRANSLATE_NOOP( "QObject", "Wed" ), QT_TRANSLATE_NOOP( "QObject", "Thu" ), QT_TRANSLATE_NOOP( "QObject", "Fri" ), QT_TRANSLATE_NOOP( "QObject", "Sat" ), QT_TRANSLATE_NOOP( "QObject", "Sun" ) }; // just create a shorter time String QDateTime dtTmp = QDateTime::currentDateTime(); QString strTime; strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + timeString( dtTmp.time(), ampm, seconds ); return strTime; } QString TimeString::dateString( const QDateTime &t, bool ampm ) { return dateString(t,ampm,FALSE); } QString TimeString::timeString( const QTime &t, bool ampm) { return timeString(t,ampm,FALSE); } QString TimeString::shortTime( bool ampm ) { return shortTime(ampm,FALSE); } +QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) +{ + return dtf.numberDate(d); +} +QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) +{ + return dtf.numberDate(d,DateFormat::longNumber); +} + #include "timestring.moc" |