Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Attributes
nsScriptableDateFormat Class Reference
Inheritance diagram for nsScriptableDateFormat:
Inheritance graph
[legend]
Collaboration diagram for nsScriptableDateFormat:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_IMETHOD FormatDateTime (const PRUnichar *locale, nsDateFormatSelector dateFormatSelector, nsTimeFormatSelector timeFormatSelector, PRInt32 year, PRInt32 month, PRInt32 day, PRInt32 hour, PRInt32 minute, PRInt32 second, PRUnichar **dateTimeString)
NS_IMETHOD FormatDate (const PRUnichar *locale, nsDateFormatSelector dateFormatSelector, PRInt32 year, PRInt32 month, PRInt32 day, PRUnichar **dateString)
NS_IMETHOD FormatTime (const PRUnichar *locale, nsTimeFormatSelector timeFormatSelector, PRInt32 hour, PRInt32 minute, PRInt32 second, PRUnichar **timeString)
 nsScriptableDateFormat ()
virtual ~nsScriptableDateFormat ()
wstring FormatDateTime (in wstring locale, in long dateFormatSelector, in long timeFormatSelector, in long year, in long month, in long day, in long hour, in long minute, in long second)
wstring FormatDate (in wstring locale, in long dateFormatSelector, in long year, in long month, in long day)
wstring FormatTime (in wstring locale, in long timeFormatSelector, in long hour, in long minute, in long second)

Public Attributes

const long dateFormatNone = 0
const long dateFormatLong = 1
const long dateFormatShort = 2
const long dateFormatYearMonth = 3
const long dateFormatWeekday = 4
const long timeFormatNone = 0
const long timeFormatSeconds = 1
const long timeFormatNoSeconds = 2
const long timeFormatSecondsForce24Hour = 3
const long timeFormatNoSecondsForce24Hour = 4

Private Attributes

nsString mStringOut

Detailed Description

Definition at line 53 of file nsScriptableDateFormat.cpp.


Constructor & Destructor Documentation

Definition at line 86 of file nsScriptableDateFormat.cpp.

{}
virtual nsScriptableDateFormat::~nsScriptableDateFormat ( ) [inline, virtual]

Definition at line 87 of file nsScriptableDateFormat.cpp.

{}

Member Function Documentation

NS_IMETHOD nsScriptableDateFormat::FormatDate ( const PRUnichar locale,
nsDateFormatSelector  dateFormatSelector,
PRInt32  year,
PRInt32  month,
PRInt32  day,
PRUnichar **  dateString 
) [inline]

Definition at line 68 of file nsScriptableDateFormat.cpp.

                        {return FormatDateTime(locale, dateFormatSelector, kTimeFormatNone, 
                                               year, month, day, 0, 0, 0, dateString);}

Here is the call graph for this function:

wstring nsIScriptableDateFormat::FormatDate ( in wstring  locale,
in long  dateFormatSelector,
in long  year,
in long  month,
in long  day 
) [inherited]

Here is the caller graph for this function:

NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime ( const PRUnichar locale,
nsDateFormatSelector  dateFormatSelector,
nsTimeFormatSelector  timeFormatSelector,
PRInt32  year,
PRInt32  month,
PRInt32  day,
PRInt32  hour,
PRInt32  minute,
PRInt32  second,
PRUnichar **  dateTimeString 
)

Definition at line 94 of file nsScriptableDateFormat.cpp.

{
  nsresult rv;
  nsAutoString localeName(aLocale);
  *dateTimeString = nsnull;

  nsCOMPtr<nsILocale> locale;
  // re-initialise locale pointer only if the locale was given explicitly
  if (!localeName.IsEmpty()) {
    // get locale service
    nsCOMPtr<nsILocaleService> localeService(do_GetService(kLocaleServiceCID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);
    // get locale
    rv = localeService->NewLocale(localeName, getter_AddRefs(locale));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nsCOMPtr<nsIDateTimeFormat> dateTimeFormat(do_CreateInstance(kDateTimeFormatCID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  tm tmTime;
  time_t timetTime;

  memset(&tmTime, 0, sizeof(tmTime));
  tmTime.tm_year = year - 1900;
  tmTime.tm_mon = month - 1;
  tmTime.tm_mday = day;
  tmTime.tm_hour = hour;
  tmTime.tm_min = minute;
  tmTime.tm_sec = second;
  tmTime.tm_yday = tmTime.tm_wday = 0;
  tmTime.tm_isdst = -1;
  timetTime = mktime(&tmTime);

  if ((time_t)-1 != timetTime) {
    rv = dateTimeFormat->FormatTime(locale, dateFormatSelector, timeFormatSelector, 
                                     timetTime, mStringOut);
  }
  else {
    // 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))
      return NS_ERROR_ILLEGAL_VALUE; // invalid arg value

    rv = dateTimeFormat->FormatPRTime(locale, dateFormatSelector, timeFormatSelector, 
                                      prtime, mStringOut);
  }
  if (NS_SUCCEEDED(rv))
    *dateTimeString = ToNewUnicode(mStringOut);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

wstring nsIScriptableDateFormat::FormatDateTime ( in wstring  locale,
in long  dateFormatSelector,
in long  timeFormatSelector,
in long  year,
in long  month,
in long  day,
in long  hour,
in long  minute,
in long  second 
) [inherited]

Here is the caller graph for this function:

NS_IMETHOD nsScriptableDateFormat::FormatTime ( const PRUnichar locale,
nsTimeFormatSelector  timeFormatSelector,
PRInt32  hour,
PRInt32  minute,
PRInt32  second,
PRUnichar **  timeString 
) [inline]

Definition at line 77 of file nsScriptableDateFormat.cpp.

                        {return FormatDateTime(locale, kDateFormatNone, timeFormatSelector, 
                                               1999, 1, 1, hour, minute, second, timeString);}

Here is the call graph for this function:

wstring nsIScriptableDateFormat::FormatTime ( in wstring  locale,
in long  timeFormatSelector,
in long  hour,
in long  minute,
in long  second 
) [inherited]

Here is the caller graph for this function:


Member Data Documentation

Definition at line 80 of file nsIScriptableDateFormat.idl.

Definition at line 79 of file nsIScriptableDateFormat.idl.

Definition at line 81 of file nsIScriptableDateFormat.idl.

Definition at line 83 of file nsIScriptableDateFormat.idl.

Definition at line 82 of file nsIScriptableDateFormat.idl.

Definition at line 89 of file nsScriptableDateFormat.cpp.

Definition at line 93 of file nsIScriptableDateFormat.idl.

Definition at line 95 of file nsIScriptableDateFormat.idl.

Definition at line 97 of file nsIScriptableDateFormat.idl.

Definition at line 94 of file nsIScriptableDateFormat.idl.

Definition at line 96 of file nsIScriptableDateFormat.idl.


The documentation for this class was generated from the following file: