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,47 +195,51 @@ nsresult nsDateTimeFormatUnix::FormatTMTime(nsILocale* locale,
NS_ENSURE_TRUE(mDecoder, NS_ERROR_NOT_INITIALIZED);
// set date format
switch (dateFormatSelector) {
case kDateFormatNone:
PL_strncpy(fmtD, "", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kDateFormatLong:
case kDateFormatShort:
PL_strncpy(fmtD, "%x", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kDateFormatYearMonth:
PL_strncpy(fmtD, "%y/%m", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kDateFormatWeekday:
PL_strncpy(fmtD, "%a", NSDATETIME_FORMAT_BUFFER_LEN);
break;
default:
PL_strncpy(fmtD, "", NSDATETIME_FORMAT_BUFFER_LEN);
}
if (dateFormatSelector == kDateFormatLong && timeFormatSelector == kTimeFormatSeconds) {
PL_strncpy(fmtD, "%c", NSDATETIME_FORMAT_BUFFER_LEN);
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
} else {
// set time format
switch (timeFormatSelector) {
case kTimeFormatNone:
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);
break;
case kTimeFormatNoSeconds:
PL_strncpy(fmtT,
mLocalePreferred24hour ? "%H:%M" : mLocaleAMPMfirst ? "%p %I:%M" : "%I:%M %p",
NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatSecondsForce24Hour:
PL_strncpy(fmtT, "%H:%M:%S", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatNoSecondsForce24Hour:
PL_strncpy(fmtT, "%H:%M", NSDATETIME_FORMAT_BUFFER_LEN);
break;
default:
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
switch (dateFormatSelector) {
case kDateFormatNone:
PL_strncpy(fmtD, "", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kDateFormatLong:
case kDateFormatShort:
PL_strncpy(fmtD, "%x", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kDateFormatYearMonth:
PL_strncpy(fmtD, "%y/%m", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kDateFormatWeekday:
PL_strncpy(fmtD, "%a", NSDATETIME_FORMAT_BUFFER_LEN);
break;
default:
PL_strncpy(fmtD, "", NSDATETIME_FORMAT_BUFFER_LEN);
}
// set time format
switch (timeFormatSelector) {
case kTimeFormatNone:
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatSeconds:
PL_strncpy(fmtT, "%X", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatNoSeconds:
PL_strncpy(fmtT,
mLocalePreferred24hour ? "%H:%M" : mLocaleAMPMfirst ? "%p %I:%M" : "%I:%M %p",
NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatSecondsForce24Hour:
PL_strncpy(fmtT, "%H:%M:%S", NSDATETIME_FORMAT_BUFFER_LEN);
break;
case kTimeFormatNoSecondsForce24Hour:
PL_strncpy(fmtT, "%H:%M", NSDATETIME_FORMAT_BUFFER_LEN);
break;
default:
PL_strncpy(fmtT, "", NSDATETIME_FORMAT_BUFFER_LEN);
}
}
// generate data/time string

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());
}
}