mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
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:
parent
9c182a96ff
commit
bcadc4523e
@ -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);
|
||||
|
40
intl/locale/tests/unit/test_bug374040.js
Normal file
40
intl/locale/tests/unit/test_bug374040.js
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user