Added progid/cid to idl and interface change.

This commit is contained in:
nhotta%netscape.com 1999-08-04 21:36:36 +00:00
Родитель 171ed12851
Коммит f37eb606f8
3 изменённых файлов: 50 добавлений и 32 удалений

Просмотреть файл

@ -42,32 +42,39 @@ enum
}; };
%} %}
%{C++
// Define Progid and CID
// {2EA2E7D0-4095-11d3-9144-006008A6EDF6}
#define NS_SCRIPTABLEDATEFORMAT_CID \
{ 0x2ea2e7d0, 0x4095, 0x11d3, { 0x91, 0x44, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
#define NS_SCRIPTABLEDATEFORMAT_PROGID "component://netscape/intl/scriptabledateformat"
extern nsISupports *NEW_SCRIPTABLE_DATEFORMAT(void);
%}
[scriptable, uuid(0c89efb0-1aae-11d3-9141-006008a6edf6)] [scriptable, uuid(0c89efb0-1aae-11d3-9141-006008a6edf6)]
interface nsIScriptableDateFormat : nsISupports { interface nsIScriptableDateFormat : nsISupports {
// format date and time, locale is language country pair (e.g. en-US) or empty string for application default // format date and time, locale is language country pair (e.g. en-US) or empty string for application default
void FormatDateTime(in wstring locale, wstring FormatDateTime(in wstring locale,
in nsDateFormatSelector dateFormatSelector, in nsDateFormatSelector dateFormatSelector,
in nsTimeFormatSelector timeFormatSelector, in nsTimeFormatSelector timeFormatSelector,
in long year, in long year,
in long month, in long month,
in long day, in long day,
in long hour, in long hour,
in long minute, in long minute,
in long second, in long second);
[shared, retval] out wstring dateTimeString);
// format date, locale is language country pair (e.g. en-US) or empty string for application default // format date, locale is language country pair (e.g. en-US) or empty string for application default
void FormatDate(in wstring locale, wstring FormatDate(in wstring locale,
in nsDateFormatSelector dateFormatSelector, in nsDateFormatSelector dateFormatSelector,
in long year, in long year,
in long month, in long month,
in long day, in long day);
[shared, retval] out wstring dateString);
// format time, locale is language country pair (e.g. en-US) or empty string for application default // format time, locale is language country pair (e.g. en-US) or empty string for application default
void FormatTime(in wstring locale, wstring FormatTime(in wstring locale,
in nsTimeFormatSelector timeFormatSelector, in nsTimeFormatSelector timeFormatSelector,
in long hour, in long hour,
in long minute, in long minute,
in long second, in long second);
[shared, retval] out wstring timeString);
}; };

Просмотреть файл

@ -28,7 +28,5 @@
{ 0x704e7c0, 0xa758, 0x11d2, \ { 0x704e7c0, 0xa758, 0x11d2, \
{ 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } } { 0x91, 0x19, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
nsISupports *NEW_SCRIPTABLE_DATEFORMAT(void);
#endif // nsDateTimeFormatCID_h__ #endif // nsDateTimeFormatCID_h__

Просмотреть файл

@ -41,14 +41,14 @@ class nsScriptableDateFormat : public nsIScriptableDateFormat {
PRInt32 hour, PRInt32 hour,
PRInt32 minute, PRInt32 minute,
PRInt32 second, PRInt32 second,
const PRUnichar **dateTimeString); PRUnichar **dateTimeString);
NS_IMETHOD FormatDate(const PRUnichar *locale, NS_IMETHOD FormatDate(const PRUnichar *locale,
nsDateFormatSelector dateFormatSelector, nsDateFormatSelector dateFormatSelector,
PRInt32 year, PRInt32 year,
PRInt32 month, PRInt32 month,
PRInt32 day, PRInt32 day,
const PRUnichar **dateString) PRUnichar **dateString)
{return FormatDateTime(locale, dateFormatSelector, kTimeFormatNone, {return FormatDateTime(locale, dateFormatSelector, kTimeFormatNone,
year, month, day, 0, 0, 0, dateString);} year, month, day, 0, 0, 0, dateString);}
@ -57,7 +57,7 @@ class nsScriptableDateFormat : public nsIScriptableDateFormat {
PRInt32 hour, PRInt32 hour,
PRInt32 minute, PRInt32 minute,
PRInt32 second, PRInt32 second,
const PRUnichar **timeString) PRUnichar **timeString)
{return FormatDateTime(locale, kDateFormatNone, timeFormatSelector, {return FormatDateTime(locale, kDateFormatNone, timeFormatSelector,
1999, 1, 1, hour, minute, second, timeString);} 1999, 1, 1, hour, minute, second, timeString);}
@ -79,7 +79,7 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
PRInt32 hour, PRInt32 hour,
PRInt32 minute, PRInt32 minute,
PRInt32 second, PRInt32 second,
const PRUnichar **dateTimeString) PRUnichar **dateTimeString)
{ {
nsILocaleFactory* localeFactory; nsILocaleFactory* localeFactory;
nsILocale* aLocale; nsILocale* aLocale;
@ -101,7 +101,7 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
struct tm tmTime; struct tm tmTime;
time_t timetTime; time_t timetTime;
nsCRT::memset( &tmTime, 0, sizeof(tmTime) ); nsCRT::memset( &tmTime, 0, sizeof(tmTime) );
tmTime.tm_year = year - 1900; tmTime.tm_year = year - 1900;
tmTime.tm_mon = month - 1; tmTime.tm_mon = month - 1;
tmTime.tm_mday = day; tmTime.tm_mday = day;
@ -113,13 +113,26 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
timetTime = mktime(&tmTime); timetTime = mktime(&tmTime);
if (-1 != timetTime) { if (-1 != timetTime) {
rv = aDateTimeFormat->FormatTime(aLocale, dateFormatSelector, timeFormatSelector, rv = aDateTimeFormat->FormatTime(aLocale, dateFormatSelector, timeFormatSelector,
timetTime, mStringOut); timetTime, mStringOut);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
*dateTimeString = mStringOut.GetUnicode(); *dateTimeString = mStringOut.ToNewUnicode();
} }
} }
else { else {
rv = NS_ERROR_ILLEGAL_VALUE; // invalid arg value // if mktime fails (e.g. year <= 1970), then try NSPR.
PRTime prtime;
char string[32];
sprintf(string, "%.2d/%.2d/%d %.2d:%.2d:%.2d", month, day, year, hour, minute, second);
if (PR_SUCCESS != PR_ParseTimeString(string, PR_FALSE, &prtime)) {
rv = NS_ERROR_ILLEGAL_VALUE; // invalid arg value
}
else {
rv = aDateTimeFormat->FormatPRTime(aLocale, dateFormatSelector, timeFormatSelector,
prtime, mStringOut);
if (NS_SUCCEEDED(rv)) {
*dateTimeString = mStringOut.ToNewUnicode();
}
}
} }
NS_RELEASE(aDateTimeFormat); NS_RELEASE(aDateTimeFormat);
} }