summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 4960b9a..7bd8a70 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -285,104 +285,112 @@ QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat
285 case 'y': 285 case 'y':
286 put_it_in( buffer, index, pDate.year() % 100 ); 286 put_it_in( buffer, index, pDate.year() % 100 );
287 break; 287 break;
288 case 'n': 288 case 'n':
289 number = pDate.month(); 289 number = pDate.month();
290 case 'e': 290 case 'e':
291 // to share the code 291 // to share the code
292 if ( rst.at( format_index ).unicode() == 'e' ) 292 if ( rst.at( format_index ).unicode() == 'e' )
293 number = pDate.day(); 293 number = pDate.day();
294 if ( number / 10 ) 294 if ( number / 10 )
295 buffer[index++] = number / 10 + '0'; 295 buffer[index++] = number / 10 + '0';
296 buffer[index++] = number % 10 + '0'; 296 buffer[index++] = number % 10 + '0';
297 break; 297 break;
298 case 'm': 298 case 'm':
299 put_it_in( buffer, index, pDate.month() ); 299 put_it_in( buffer, index, pDate.month() );
300 break; 300 break;
301 case 'b': 301 case 'b':
302 put_it_in( buffer, index, monthName(pDate.month(), true) ); 302 put_it_in( buffer, index, monthName(pDate.month(), true) );
303 break; 303 break;
304 case 'B': 304 case 'B':
305 put_it_in( buffer, index, monthName(pDate.month(), false) ); 305 put_it_in( buffer, index, monthName(pDate.month(), false) );
306 break; 306 break;
307 case 'd': 307 case 'd':
308 put_it_in( buffer, index, pDate.day() ); 308 put_it_in( buffer, index, pDate.day() );
309 break; 309 break;
310 case 'a': 310 case 'a':
311 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); 311 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) );
312 break; 312 break;
313 case 'A': 313 case 'A':
314 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); 314 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) );
315 break; 315 break;
316 default: 316 default:
317 buffer[index++] = rst.at( format_index ); 317 buffer[index++] = rst.at( format_index );
318 break; 318 break;
319 } 319 }
320 escape = false; 320 escape = false;
321 } 321 }
322 } 322 }
323 QString ret( buffer, index ); 323 QString ret( buffer, index );
324 delete [] buffer; 324 delete [] buffer;
325 return ret; 325 return ret;
326} 326}
327 327
328QString KLocale::formatDateTime(const QDateTime &pDateTime, 328QString KLocale::formatDateTime(const QDateTime &pDateTime,
329 bool shortFormat, 329 bool shortFormat,
330 bool includeSeconds, 330 bool includeSeconds,
331 IntDateFormat intIntDateFormat) const 331 IntDateFormat intIntDateFormat) const
332{ 332{
333 return QString( "%1 %2") 333 QString format("%1 %2");
334 .arg( formatDate( pDateTime.date(), shortFormat, intIntDateFormat ) ) 334
335 .arg( formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ) ); 335 if ( intIntDateFormat == Default )
336 format = "%1 %2";
337 else if ( intIntDateFormat == Format1 )
338 format = "%1 %2";
339 else if ( intIntDateFormat == ISODate )
340 format = "%1T%2";
341
342 return format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat ))
343 .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ));
336} 344}
337 345
338QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const 346QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
339{ 347{
340 return formatDateTime(pDateTime, true, intIntDateFormat); 348 return formatDateTime(pDateTime, true, true, intIntDateFormat);
341} 349}
342 350
343QDate KLocale::readDate(const QString &intstr, bool* ok) const 351QDate KLocale::readDate(const QString &intstr, bool* ok) const
344{ 352{
345 QDate date; 353 QDate date;
346 date = readDate(intstr, true, ok); 354 date = readDate(intstr, true, ok);
347 if (date.isValid()) return date; 355 if (date.isValid()) return date;
348 return readDate(intstr, false, ok); 356 return readDate(intstr, false, ok);
349} 357}
350 358
351QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const 359QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const
352{ 360{
353 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); 361 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
354 return readDate( intstr, fmt, ok ); 362 return readDate( intstr, fmt, ok );
355} 363}
356 364
357QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const 365QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const
358{ 366{
359 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; 367 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
360 QString str = intstr.simplifyWhiteSpace().lower(); 368 QString str = intstr.simplifyWhiteSpace().lower();
361 int day = -1, month = -1; 369 int day = -1, month = -1;
362 // allow the year to be omitted if not in the format 370 // allow the year to be omitted if not in the format
363 int year = QDate::currentDate().year(); 371 int year = QDate::currentDate().year();
364 uint strpos = 0; 372 uint strpos = 0;
365 uint fmtpos = 0; 373 uint fmtpos = 0;
366 374
367 while (fmt.length() > fmtpos || str.length() > strpos) 375 while (fmt.length() > fmtpos || str.length() > strpos)
368 { 376 {
369 if ( !(fmt.length() > fmtpos && str.length() > strpos) ) 377 if ( !(fmt.length() > fmtpos && str.length() > strpos) )
370 goto error; 378 goto error;
371 379
372 QChar c = fmt.at(fmtpos++); 380 QChar c = fmt.at(fmtpos++);
373 381
374 if (c != '%') { 382 if (c != '%') {
375 if (c.isSpace()) 383 if (c.isSpace())
376 strpos++; 384 strpos++;
377 else if (c != str.at(strpos++)) 385 else if (c != str.at(strpos++))
378 goto error; 386 goto error;
379 continue; 387 continue;
380 } 388 }
381 389
382 // remove space at the begining 390 // remove space at the begining
383 if (str.length() > strpos && str.at(strpos).isSpace()) 391 if (str.length() > strpos && str.at(strpos).isSpace())
384 strpos++; 392 strpos++;
385 393
386 c = fmt.at(fmtpos++); 394 c = fmt.at(fmtpos++);
387 switch (c) 395 switch (c)
388 { 396 {
@@ -525,96 +533,112 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
525 case 'H': 533 case 'H':
526 g_12h = false; 534 g_12h = false;
527 hour = readInt(str, strpos); 535 hour = readInt(str, strpos);
528 if (hour < 0 || hour > 23) 536 if (hour < 0 || hour > 23)
529 goto error; 537 goto error;
530 538
531 break; 539 break;
532 540
533 case 'l': 541 case 'l':
534 case 'I': 542 case 'I':
535 g_12h = true; 543 g_12h = true;
536 hour = readInt(str, strpos); 544 hour = readInt(str, strpos);
537 if (hour < 1 || hour > 12) 545 if (hour < 1 || hour > 12)
538 goto error; 546 goto error;
539 547
540 break; 548 break;
541 549
542 case 'M': 550 case 'M':
543 minute = readInt(str, strpos); 551 minute = readInt(str, strpos);
544 if (minute < 0 || minute > 59) 552 if (minute < 0 || minute > 59)
545 goto error; 553 goto error;
546 554
547 break; 555 break;
548 556
549 case 'S': 557 case 'S':
550 second = readInt(str, strpos); 558 second = readInt(str, strpos);
551 if (second < 0 || second > 59) 559 if (second < 0 || second > 59)
552 goto error; 560 goto error;
553 561
554 break; 562 break;
555 } 563 }
556 } 564 }
557 if (g_12h) 565 if (g_12h)
558 { 566 {
559 hour %= 12; 567 hour %= 12;
560 if (pm) hour += 12; 568 if (pm) hour += 12;
561 } 569 }
562 570
563 if (ok) *ok = true; 571 if (ok) *ok = true;
564 return QTime(hour, minute, second); 572 return QTime(hour, minute, second);
565 573
566 error: 574 error:
567 if (ok) *ok = false; 575 if (ok) *ok = false;
568 return QTime(-1, -1, -1); // return invalid date if it didn't work 576 return QTime(-1, -1, -1); // return invalid date if it didn't work
569 // This will be removed in the near future, since it gives a warning on stderr. 577 // This will be removed in the near future, since it gives a warning on stderr.
570 // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. 578 // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime.
571} 579}
572 580
581QDateTime KLocale::readDateTime(const QString &intstr,
582 bool shortFormat,
583 bool includeSeconds,
584 IntDateFormat intIntDateFormat,
585 bool* ok) const
586{
587 bool ok1, ok2;
588
589 QDate m_date = readDate(date, &ok1);
590 QTime m_time = KGlobal::locale()->readTime(time, &ok2);
591 if ((ok1 == false) || (ok2 == false))
592 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
593
594}
595
596
573bool KLocale::use12Clock() const 597bool KLocale::use12Clock() const
574{ 598{
575 return !mHourF24Format ;; 599 return !mHourF24Format ;;
576} 600}
577 601
578bool KLocale::weekStartsMonday() const 602bool KLocale::weekStartsMonday() const
579{ 603{
580 return mWeekStartsMonday; 604 return mWeekStartsMonday;
581} 605}
582 606
583int KLocale::weekStartDay() const 607int KLocale::weekStartDay() const
584{ 608{
585 if ( mWeekStartsMonday ) 609 if ( mWeekStartsMonday )
586 return 1; 610 return 1;
587 return 7; 611 return 7;
588} 612}
589 613
590QString KLocale::weekDayName(int i,bool shortName) const 614QString KLocale::weekDayName(int i,bool shortName) const
591{ 615{
592 if ( shortName ) 616 if ( shortName )
593 switch ( i ) 617 switch ( i )
594 { 618 {
595 case 1: return i18n("Monday", "Mon"); 619 case 1: return i18n("Monday", "Mon");
596 case 2: return i18n("Tuesday", "Tue"); 620 case 2: return i18n("Tuesday", "Tue");
597 case 3: return i18n("Wednesday", "Wed"); 621 case 3: return i18n("Wednesday", "Wed");
598 case 4: return i18n("Thursday", "Thu"); 622 case 4: return i18n("Thursday", "Thu");
599 case 5: return i18n("Friday", "Fri"); 623 case 5: return i18n("Friday", "Fri");
600 case 6: return i18n("Saturday", "Sat"); 624 case 6: return i18n("Saturday", "Sat");
601 case 7: return i18n("Sunday", "Sun"); 625 case 7: return i18n("Sunday", "Sun");
602 } 626 }
603 else 627 else
604 switch ( i ) 628 switch ( i )
605 { 629 {
606 case 1: return i18n("Monday"); 630 case 1: return i18n("Monday");
607 case 2: return i18n("Tuesday"); 631 case 2: return i18n("Tuesday");
608 case 3: return i18n("Wednesday"); 632 case 3: return i18n("Wednesday");
609 case 4: return i18n("Thursday"); 633 case 4: return i18n("Thursday");
610 case 5: return i18n("Friday"); 634 case 5: return i18n("Friday");
611 case 6: return i18n("Saturday"); 635 case 6: return i18n("Saturday");
612 case 7: return i18n("Sunday"); 636 case 7: return i18n("Sunday");
613 } 637 }
614 638
615 return QString::null; 639 return QString::null;
616} 640}
617 641
618QString KLocale::monthName(int i,bool shortName) const 642QString KLocale::monthName(int i,bool shortName) const
619{ 643{
620 if ( shortName ) 644 if ( shortName )