Bug 374040 - "nsIScriptableDateFormat does not work as expected with dateFormatLong" [p=arenevier@fdn.fr (arno.) r=smontagu a1.9=schrep]

This commit is contained in:
reed@reedloden.com 2008-01-29 20:30:20 -08:00
parent 9c182a96ff
commit bcadc4523e
2 changed files with 84 additions and 40 deletions

View File

@ -195,6 +195,11 @@ nsresult nsDateTimeFormatUnix::FormatTMTime(nsILocale* locale,
NS_ENSURE_TRUE(mDecoder, NS_ERROR_NOT_INITIALIZED);
// set date format
if (dateFormatSelector == kDateFormatLong && timeFormatSelector == kTimeFormatSeconds) {
PL_strncpy(fmtD, "%c", NSDATETIME_FORMAT_BUFFER_LEN);
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
} else {
switch (dateFormatSelector) {
case kDateFormatNone:
PL_strncpy(fmtD, "", NSDATETIME_FORMAT_BUFFER_LEN);
@ -219,9 +224,7 @@ nsresult nsDateTimeFormatUnix::FormatTMTime(nsILocale* locale,
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatSeconds:
PL_strncpy(fmtT,
mLocalePreferred24hour ? "%H:%M:%S" : mLocaleAMPMfirst ? "%p %I:%M:%S" : "%I:%M:%S %p",
NSDATETIME_FORMAT_BUFFER_LEN);
PL_strncpy(fmtT, "%X", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatNoSeconds:
PL_strncpy(fmtT,
@ -237,6 +240,7 @@ nsresult nsDateTimeFormatUnix::FormatTMTime(nsILocale* locale,
default:
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
}
}
// generate data/time string
char *old_locale = setlocale(LC_TIME, NULL);

View File

@ -0,0 +1,40 @@
function test_full() {
var date = new Date();
var scriptableDateServ =
Components.classes["@mozilla.org/intl/scriptabledateformat;1"].createInstance(Components.interfaces.nsIScriptableDateFormat);
var dateStrXpcom = scriptableDateServ.FormatDateTime("",
scriptableDateServ.dateFormatLong, scriptableDateServ.timeFormatSeconds,
date.getFullYear(), date.getMonth()+1, date.getDate(), date.getHours(),
date.getMinutes(), date.getSeconds());
var dateStrJs = date.toLocaleString();
return (dateStrXpcom == dateStrJs);
}
function test_kTimeFormatSeconds() {
var date = new Date();
var scriptableDateServ =
Components.classes["@mozilla.org/intl/scriptabledateformat;1"].createInstance(Components.interfaces.nsIScriptableDateFormat);
var dateStrXpcom = scriptableDateServ.FormatDateTime("",
scriptableDateServ.dateFormatLong, scriptableDateServ.timeFormatNone,
date.getFullYear(), date.getMonth()+1, date.getDate(), date.getHours(),
date.getMinutes(), date.getSeconds());
var dateStrJs = date.toLocaleDateString()
return (dateStrXpcom == dateStrJs);
}
function run_test()
{
var os = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS;
if (os == "Linux" || os == "SunOS" || os == "IRIX" || os == "AIX") {
do_check_true(test_full());
do_check_true(test_kTimeFormatSeconds());
}
}