summaryrefslogtreecommitdiffabout
path: root/microkde
Side-by-side diff
Diffstat (limited to 'microkde') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 8b4513e..27acfec 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -246,194 +246,198 @@ QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat
break;
}
escape = false;
}
}
QString ret( buffer, index );
delete [] buffer;
return ret;
}
QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const
{
const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat);
// I'm rather safe than sorry
QChar *buffer = new QChar[rst.length() * 3 / 2 + 50];
unsigned int index = 0;
bool escape = false;
int number = 0;
for ( uint format_index = 0; format_index < rst.length(); ++format_index )
{
if ( !escape )
{
if ( rst.at( format_index ).unicode() == '%' )
escape = true;
else
buffer[index++] = rst.at( format_index );
}
else
{
switch ( rst.at( format_index ).unicode() )
{
case '%':
buffer[index++] = '%';
break;
case 'Y':
put_it_in( buffer, index, pDate.year() / 100 );
case 'y':
put_it_in( buffer, index, pDate.year() % 100 );
break;
case 'n':
number = pDate.month();
case 'e':
// to share the code
if ( rst.at( format_index ).unicode() == 'e' )
number = pDate.day();
if ( number / 10 )
buffer[index++] = number / 10 + '0';
buffer[index++] = number % 10 + '0';
break;
case 'm':
put_it_in( buffer, index, pDate.month() );
break;
case 'b':
put_it_in( buffer, index, monthName(pDate.month(), true) );
break;
case 'B':
put_it_in( buffer, index, monthName(pDate.month(), false) );
break;
case 'd':
put_it_in( buffer, index, pDate.day() );
break;
case 'a':
put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) );
break;
case 'A':
put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) );
break;
default:
buffer[index++] = rst.at( format_index );
break;
}
escape = false;
}
}
QString ret( buffer, index );
delete [] buffer;
return ret;
}
QString KLocale::formatDateTime(const QDateTime &pDateTime,
bool shortFormat,
bool includeSeconds,
IntDateFormat intIntDateFormat) const
{
QString format("%1 %2");
if ( intIntDateFormat == Default )
format = "%1 %2";
else if ( intIntDateFormat == Format1 )
format = "%1 %2";
else if ( intIntDateFormat == ISODate )
format = "%1T%2";
- return format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat ))
+ QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat ))
.arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ));
+
+ //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() );
+
+ return res;
}
QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
{
return formatDateTime(pDateTime, true, true, intIntDateFormat);
}
QDate KLocale::readDate(const QString &intstr, bool* ok) const
{
QDate date;
date = readDate(intstr, true, ok);
if (date.isValid()) return date;
return readDate(intstr, false, ok);
}
QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const
{
QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
return readDate( intstr, fmt, ok );
}
QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const
{
//kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
QString str = intstr.simplifyWhiteSpace().lower();
int day = -1, month = -1;
// allow the year to be omitted if not in the format
int year = QDate::currentDate().year();
uint strpos = 0;
uint fmtpos = 0;
while (fmt.length() > fmtpos || str.length() > strpos)
{
if ( !(fmt.length() > fmtpos && str.length() > strpos) )
goto error;
QChar c = fmt.at(fmtpos++);
if (c != '%') {
if (c.isSpace())
strpos++;
else if (c != str.at(strpos++))
goto error;
continue;
}
// remove space at the begining
if (str.length() > strpos && str.at(strpos).isSpace())
strpos++;
c = fmt.at(fmtpos++);
switch (c)
{
case 'a':
case 'A':
// this will just be ignored
{ // Cristian Tache: porting to Win: Block added because of "j" redefinition
for (int j = 1; j < 8; j++) {
QString s = weekDayName(j, c == 'a').lower();
int len = s.length();
if (str.mid(strpos, len) == s)
strpos += len;
}
break;
}
case 'b':
case 'B':
{ // Cristian Tache: porting to Win: Block added because of "j" redefinition
for (int j = 1; j < 13; j++) {
QString s = monthName(j, c == 'b').lower();
int len = s.length();
if (str.mid(strpos, len) == s) {
month = j;
strpos += len;
}
}
break;
}
case 'd':
case 'e':
day = readInt(str, strpos);
if (day < 1 || day > 31)
goto error;
break;
case 'n':
case 'm':
month = readInt(str, strpos);
if (month < 1 || month > 12)
goto error;
break;
case 'Y':
case 'y':
@@ -508,204 +512,210 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
case 'p':
{
QString s;
s = i18n("pm").lower();
int len = s.length();
if (str.mid(strpos, len) == s)
{
pm = true;
strpos += len;
}
else
{
s = i18n("am").lower();
len = s.length();
if (str.mid(strpos, len) == s) {
pm = false;
strpos += len;
}
else
goto error;
}
}
break;
case 'k':
case 'H':
g_12h = false;
hour = readInt(str, strpos);
if (hour < 0 || hour > 23)
goto error;
break;
case 'l':
case 'I':
g_12h = true;
hour = readInt(str, strpos);
if (hour < 1 || hour > 12)
goto error;
break;
case 'M':
minute = readInt(str, strpos);
if (minute < 0 || minute > 59)
goto error;
break;
case 'S':
second = readInt(str, strpos);
if (second < 0 || second > 59)
goto error;
break;
}
}
if (g_12h)
{
hour %= 12;
if (pm) hour += 12;
}
if (ok) *ok = true;
return QTime(hour, minute, second);
error:
if (ok) *ok = false;
return QTime(-1, -1, -1); // return invalid date if it didn't work
// This will be removed in the near future, since it gives a warning on stderr.
// The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime.
}
QDateTime KLocale::readDateTime(const QString &intstr,
IntDateFormat intIntDateFormat,
bool* ok) const
{
bool ok1, ok2;
// AT the moment we can not read any other format then ISODate
if ( intIntDateFormat != ISODate )
{
qDebug("KLocale::readDateTime, only ISODate is supported.");
return QDateTime();
}
int pos = intstr.find("T");
QString date = intstr.left(pos);
QString time = intstr.mid(pos+1);
QString dformat = dateFormat(intIntDateFormat);
QString tformat = timeFormat(intIntDateFormat);
QDate m_date = readDate(date, dformat, &ok1);
QTime m_time = readTime(time, tformat, &ok2);
+ QDateTime m_dt;
+
if (ok)
{
if ((ok1 == false) || (ok2 == false))
*ok = false;
else
*ok = true;
}
- QDateTime m_dt;
+
+ //only set values if both operations returned true.
+ if ((ok1 == true) && (ok2 == true))
+ {
m_dt.setDate(m_date);
m_dt.setTime(m_time);
+ }
- qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2);
+ //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2);
return m_dt;
}
QDate KLocale::readDate(const QString &intstr,
IntDateFormat intIntDateFormat,
bool* ok) const
{
bool ok1;
QString dformat = dateFormat(intIntDateFormat);
QDate m_date = readDate(intstr, dformat, &ok1);
if (ok)
*ok = ok1;
//qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2);
return m_date;
}
bool KLocale::use12Clock() const
{
return !mHourF24Format ;;
}
bool KLocale::weekStartsMonday() const
{
return mWeekStartsMonday;
}
int KLocale::weekStartDay() const
{
if ( mWeekStartsMonday )
return 1;
return 7;
}
QString KLocale::weekDayName(int i,bool shortName) const
{
if ( shortName )
switch ( i )
{
case 1: return i18n("Monday", "Mon");
case 2: return i18n("Tuesday", "Tue");
case 3: return i18n("Wednesday", "Wed");
case 4: return i18n("Thursday", "Thu");
case 5: return i18n("Friday", "Fri");
case 6: return i18n("Saturday", "Sat");
case 7: return i18n("Sunday", "Sun");
}
else
switch ( i )
{
case 1: return i18n("Monday");
case 2: return i18n("Tuesday");
case 3: return i18n("Wednesday");
case 4: return i18n("Thursday");
case 5: return i18n("Friday");
case 6: return i18n("Saturday");
case 7: return i18n("Sunday");
}
return QString::null;
}
QString KLocale::monthName(int i,bool shortName) const
{
if ( shortName )
switch ( i )
{
case 1: return i18n("January", "Jan");
case 2: return i18n("February", "Feb");
case 3: return i18n("March", "Mar");
case 4: return i18n("April", "Apr");
case 5: return i18n("May short", "May");
case 6: return i18n("June", "Jun");
case 7: return i18n("July", "Jul");
case 8: return i18n("August", "Aug");
case 9: return i18n("September", "Sep");
case 10: return i18n("October", "Oct");
case 11: return i18n("November", "Nov");
case 12: return i18n("December", "Dec");
}
else
switch (i)
{
case 1: return i18n("January");
case 2: return i18n("February");
case 3: return i18n("March");
case 4: return i18n("April");
case 5: return i18n("May long", "May");
case 6: return i18n("June");
case 7: return i18n("July");
case 8: return i18n("August");
case 9: return i18n("September");