summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@sosco.com>2009-10-29 10:20:31 (GMT)
committerShane Kearns <shane.kearns@sosco.com>2009-10-29 10:20:31 (GMT)
commitf736d889bca3ce5d33b1e5499ad8714952c67906 (patch)
tree712a1a2d35a97ffb648a44211f23bc08f2768945 /src/plugins
parenteed04255446df8a749390e14cef7672c26329f6e (diff)
downloadQt-f736d889bca3ce5d33b1e5499ad8714952c67906.zip
Qt-f736d889bca3ce5d33b1e5499ad8714952c67906.tar.gz
Qt-f736d889bca3ce5d33b1e5499ad8714952c67906.tar.bz2
Fix QDateTime on S60 3.1
S60 3.1 plugin returned empty strings for the unsupported APIs Since these APIs are needed for the most common use case of converting a QDateTime to a QString using the local format, I have implemented an emulation of the missing APIs using older APIs that are supported. Updated the autotest so it does some sanity checking on the result of local date/time conversion - it would pass instead of fail if the string was garbage before. Reviewed-by: Aleksandar Sasha Babic
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/s60/src/qlocale_3_1.cpp96
1 files changed, 91 insertions, 5 deletions
diff --git a/src/plugins/s60/src/qlocale_3_1.cpp b/src/plugins/s60/src/qlocale_3_1.cpp
index 0afd10a..beeee7f 100644
--- a/src/plugins/s60/src/qlocale_3_1.cpp
+++ b/src/plugins/s60/src/qlocale_3_1.cpp
@@ -40,23 +40,109 @@
****************************************************************************/
#include <e32std.h>
+#include <e32const.h>
+#include <e32debug.h>
-EXPORT_C void defaultFormatL(TTime&, TDes& des, const TDesC&, const TLocale&)
+_LIT(KYear, "%Y");
+_LIT(KMonth, "%M");
+_LIT(KDay, "%D");
+_LIT(KLocaleIndependent, "%F");
+static TBuf<10> dateFormat;
+static TBuf<10> timeFormat;
+
+static void initialiseDateFormat()
+{
+ if(dateFormat.Length())
+ return;
+
+ TLocale locale;
+
+ //Separator 1 is used between 1st and 2nd components of the date
+ //Separator 2 is used between 2nd and 3rd components of the date
+ //Usually they are the same, but they are allowed to be different
+ TChar s1 = locale.DateSeparator(1);
+ TChar s2 = locale.DateSeparator(2);
+ dateFormat=KLocaleIndependent;
+ switch(locale.DateFormat()) {
+ case EDateAmerican:
+ dateFormat.Append(KMonth);
+ dateFormat.Append(s1);
+ dateFormat.Append(KDay);
+ dateFormat.Append(s2);
+ dateFormat.Append(KYear);
+ break;
+ case EDateEuropean:
+ dateFormat.Append(KDay);
+ dateFormat.Append(s1);
+ dateFormat.Append(KMonth);
+ dateFormat.Append(s2);
+ dateFormat.Append(KYear);
+ break;
+ case EDateJapanese:
+ default: //it's closest to ISO format
+ dateFormat.Append(KYear);
+ dateFormat.Append(s1);
+ dateFormat.Append(KMonth);
+ dateFormat.Append(s2);
+ dateFormat.Append(KDay);
+ break;
+ }
+#ifdef _DEBUG
+ RDebug::Print(_L("Date Format \"%S\""), &dateFormat);
+#endif
+}
+
+static void initialiseTimeFormat()
+{
+ if(timeFormat.Length())
+ return;
+
+ TLocale locale;
+ //Separator 1 is used between 1st and 2nd components of the time
+ //Separator 2 is used between 2nd and 3rd components of the time
+ //Usually they are the same, but they are allowed to be different
+ TChar s1 = locale.TimeSeparator(1);
+ TChar s2 = locale.TimeSeparator(2);
+ switch(locale.TimeFormat()) {
+ case ETime12:
+ timeFormat.Append(_L("%I"));
+ break;
+ case ETime24:
+ default:
+ timeFormat.Append(_L("%H"));
+ break;
+ }
+ timeFormat.Append(s1);
+ timeFormat.Append(_L("%T"));
+ timeFormat.Append(s2);
+ timeFormat.Append(_L("%S"));
+
+#ifdef _DEBUG
+ RDebug::Print(_L("Time Format \"%S\""), &timeFormat);
+#endif
+}
+
+EXPORT_C void defaultFormatL(TTime& time, TDes& des, const TDesC& fmt, const TLocale&)
{
- des.Zero();
+ //S60 3.1 does not support format for a specific locale, so use default locale
+ time.FormatL(des, fmt);
}
+//S60 3.1 doesn't support extended locale date&time formats, so use default locale
EXPORT_C TPtrC defaultGetTimeFormatSpec(TExtendedLocale&)
{
- return TPtrC(KNullDesC);
+ initialiseTimeFormat();
+ return TPtrC(timeFormat);
}
EXPORT_C TPtrC defaultGetLongDateFormatSpec(TExtendedLocale&)
{
- return TPtrC(KNullDesC);
+ initialiseDateFormat();
+ return TPtrC(dateFormat);
}
EXPORT_C TPtrC defaultGetShortDateFormatSpec(TExtendedLocale&)
{
- return TPtrC(KNullDesC);
+ initialiseDateFormat();
+ return TPtrC(dateFormat);
}