nsIScriptableDateFormat.idl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsISupports.idl"
  6. typedef long nsDateFormatSelector;
  7. %{ C++
  8. enum
  9. {
  10. kDateFormatNone = 0, // do not include the date in the format string
  11. kDateFormatLong, // provides the long date format for the given locale
  12. kDateFormatShort, // provides the short date format for the given locale
  13. kDateFormatYearMonth, // formats using only the year and month
  14. kDateFormatWeekday // week day (e.g. Mon, Tue)
  15. };
  16. %}
  17. typedef long nsTimeFormatSelector;
  18. %{ C++
  19. enum
  20. {
  21. kTimeFormatNone = 0, // don't include the time in the format string
  22. kTimeFormatSeconds, // provides the time format with seconds in the given locale
  23. kTimeFormatNoSeconds, // provides the time format without seconds in the given locale
  24. kTimeFormatSecondsForce24Hour, // forces the time format to use the 24 clock, regardless of the locale conventions
  25. kTimeFormatNoSecondsForce24Hour // forces the time format to use the 24 clock, regardless of the locale conventions
  26. };
  27. %}
  28. %{C++
  29. // Define Contractid and CID
  30. // {2EA2E7D0-4095-11d3-9144-006008A6EDF6}
  31. #define NS_SCRIPTABLEDATEFORMAT_CID \
  32. { 0x2ea2e7d0, 0x4095, 0x11d3, { 0x91, 0x44, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } }
  33. #define NS_SCRIPTABLEDATEFORMAT_CONTRACTID "@mozilla.org/intl/scriptabledateformat;1"
  34. extern nsresult
  35. NS_NewScriptableDateFormat(nsISupports* aOuter, REFNSIID aIID, void** aResult);
  36. %}
  37. /**
  38. * Format date and time in a human readable format.
  39. */
  40. [scriptable, uuid(0c89efb0-1aae-11d3-9141-006008a6edf6)]
  41. interface nsIScriptableDateFormat : nsISupports
  42. {
  43. /**
  44. * Do not include the date in the format string.
  45. */
  46. const long dateFormatNone = 0;
  47. /**
  48. * Provide the long date format.
  49. *
  50. * NOTE:
  51. * The original definitions of dateFormatLong and dateFormatShort are from
  52. * the Windows platform.
  53. * In US English dateFormatLong output will be like:
  54. * Wednesday, January 29, 2003 4:02:14 PM
  55. * In US English dateFormatShort output will be like:
  56. * 1/29/03 4:02:14 PM
  57. * On platforms like Linux, it is rather difficult to achieve exact
  58. * same output, and since we are aiming at human readers, it does not make
  59. * sense to achieve exact same result. We will do just enough as the
  60. * platform allow us to do.
  61. */
  62. const long dateFormatLong = 1;
  63. /**
  64. * Provide the short date format. See also dateFormatLong.
  65. */
  66. const long dateFormatShort = 2;
  67. /**
  68. * Format using only the year and month.
  69. */
  70. const long dateFormatYearMonth = 3;
  71. /**
  72. * Provide the Week day (e.g. Mo, Mon, Monday or similar).
  73. */
  74. const long dateFormatWeekday = 4;
  75. /**
  76. * Don't include the time in the format string.
  77. */
  78. const long timeFormatNone = 0;
  79. /**
  80. * Provide the time format with seconds.
  81. */
  82. const long timeFormatSeconds = 1;
  83. /**
  84. * Provide the time format without seconds.
  85. */
  86. const long timeFormatNoSeconds = 2;
  87. /**
  88. * Provide the time format with seconds, and force the time format to use
  89. * 24-hour clock, regardless of the locale conventions.
  90. */
  91. const long timeFormatSecondsForce24Hour = 3;
  92. /**
  93. * Provide the time format without seconds, and force the time format to use
  94. * 24-hour clock, regardless of the locale conventions.
  95. */
  96. const long timeFormatNoSecondsForce24Hour = 4;
  97. /**
  98. * Format the given date and time in a human readable format.
  99. *
  100. * The underlying operating system is used to format the date and time.
  101. *
  102. * Pass an empty string as the locale parameter to use the OS settings with
  103. * the preferred date and time formatting given by the user.
  104. *
  105. * Pass a locale code as described in nsILocale as the locale parameter
  106. * (e.g. en-US) to use a specific locale. If the given locale is not
  107. * available, a fallback will be used.
  108. *
  109. * NOTE: The output of this method depends on the operating system and user
  110. * settings. Even if you pass a locale code as the first parameter, there
  111. * are no guarantees about which locale and exact format the returned value
  112. * uses. Even if you know the locale, the format might be customized by the
  113. * user. Therefore you should not use the returned values in contexts where
  114. * you depend on any specific format or language.
  115. *
  116. * @param locale
  117. * Locale code of locale used to format the date or an empty string
  118. * to follow user preference.
  119. * @param dateFormatSelector
  120. * Indicate which format should preferably be used for the date.
  121. * Use one of the dateFormat* constants.
  122. * @param timeFormatSelector
  123. * Indicate which format should preferably be used for the time.
  124. * Use one of the timeFormat* constants.
  125. * @param year, month, day, hour, minute and second
  126. * The date and time to be formatted, given in the computer's local
  127. * time zone.
  128. * @return The date and time formatted as human readable text according to
  129. * user preferences or the given locale.
  130. */
  131. wstring FormatDateTime(in wstring locale,
  132. in long dateFormatSelector,
  133. in long timeFormatSelector,
  134. in long year,
  135. in long month,
  136. in long day,
  137. in long hour,
  138. in long minute,
  139. in long second);
  140. /**
  141. * Format the given date in a human readable format.
  142. *
  143. * See FormatDateTime for details.
  144. */
  145. wstring FormatDate(in wstring locale,
  146. in long dateFormatSelector,
  147. in long year,
  148. in long month,
  149. in long day);
  150. /**
  151. * Format the given time in a human readable format.
  152. *
  153. * See FormatDateTime for details.
  154. */
  155. wstring FormatTime(in wstring locale,
  156. in long timeFormatSelector,
  157. in long hour,
  158. in long minute,
  159. in long second);
  160. };