michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: typedef long nsDateFormatSelector; michael@0: %{ C++ michael@0: enum michael@0: { michael@0: kDateFormatNone = 0, // do not include the date in the format string michael@0: kDateFormatLong, // provides the long date format for the given locale michael@0: kDateFormatShort, // provides the short date format for the given locale michael@0: kDateFormatYearMonth, // formats using only the year and month michael@0: kDateFormatWeekday // week day (e.g. Mon, Tue) michael@0: }; michael@0: %} michael@0: michael@0: typedef long nsTimeFormatSelector; michael@0: %{ C++ michael@0: enum michael@0: { michael@0: kTimeFormatNone = 0, // don't include the time in the format string michael@0: kTimeFormatSeconds, // provides the time format with seconds in the given locale michael@0: kTimeFormatNoSeconds, // provides the time format without seconds in the given locale michael@0: kTimeFormatSecondsForce24Hour, // forces the time format to use the 24 clock, regardless of the locale conventions michael@0: kTimeFormatNoSecondsForce24Hour // forces the time format to use the 24 clock, regardless of the locale conventions michael@0: }; michael@0: %} michael@0: michael@0: %{C++ michael@0: // Define Contractid and CID michael@0: // {2EA2E7D0-4095-11d3-9144-006008A6EDF6} michael@0: #define NS_SCRIPTABLEDATEFORMAT_CID \ michael@0: { 0x2ea2e7d0, 0x4095, 0x11d3, { 0x91, 0x44, 0x0, 0x60, 0x8, 0xa6, 0xed, 0xf6 } } michael@0: michael@0: #define NS_SCRIPTABLEDATEFORMAT_CONTRACTID "@mozilla.org/intl/scriptabledateformat;1" michael@0: michael@0: extern nsresult michael@0: NS_NewScriptableDateFormat(nsISupports* aOuter, REFNSIID aIID, void** aResult); michael@0: %} michael@0: michael@0: /** michael@0: * Format date and time in a human readable format. michael@0: */ michael@0: [scriptable, uuid(0c89efb0-1aae-11d3-9141-006008a6edf6)] michael@0: interface nsIScriptableDateFormat : nsISupports michael@0: { michael@0: /** michael@0: * Do not include the date in the format string. michael@0: */ michael@0: const long dateFormatNone = 0; michael@0: michael@0: /** michael@0: * Provide the long date format. michael@0: * michael@0: * NOTE: michael@0: * The original definitions of dateFormatLong and dateFormatShort are from michael@0: * the Windows platform. michael@0: * In US English dateFormatLong output will be like: michael@0: * Wednesday, January 29, 2003 4:02:14 PM michael@0: * In US English dateFormatShort output will be like: michael@0: * 1/29/03 4:02:14 PM michael@0: * On platforms like Linux, it is rather difficult to achieve exact michael@0: * same output, and since we are aiming at human readers, it does not make michael@0: * sense to achieve exact same result. We will do just enough as the michael@0: * platform allow us to do. michael@0: */ michael@0: const long dateFormatLong = 1; michael@0: michael@0: /** michael@0: * Provide the short date format. See also dateFormatLong. michael@0: */ michael@0: const long dateFormatShort = 2; michael@0: michael@0: /** michael@0: * Format using only the year and month. michael@0: */ michael@0: const long dateFormatYearMonth = 3; michael@0: michael@0: /** michael@0: * Provide the Week day (e.g. Mo, Mon, Monday or similar). michael@0: */ michael@0: const long dateFormatWeekday = 4; michael@0: michael@0: /** michael@0: * Don't include the time in the format string. michael@0: */ michael@0: const long timeFormatNone = 0; michael@0: michael@0: /** michael@0: * Provide the time format with seconds. michael@0: */ michael@0: const long timeFormatSeconds = 1; michael@0: michael@0: /** michael@0: * Provide the time format without seconds. michael@0: */ michael@0: const long timeFormatNoSeconds = 2; michael@0: michael@0: /** michael@0: * Provide the time format with seconds, and force the time format to use michael@0: * 24-hour clock, regardless of the locale conventions. michael@0: */ michael@0: const long timeFormatSecondsForce24Hour = 3; michael@0: michael@0: /** michael@0: * Provide the time format without seconds, and force the time format to use michael@0: * 24-hour clock, regardless of the locale conventions. michael@0: */ michael@0: const long timeFormatNoSecondsForce24Hour = 4; michael@0: michael@0: /** michael@0: * Format the given date and time in a human readable format. michael@0: * michael@0: * The underlying operating system is used to format the date and time. michael@0: * michael@0: * Pass an empty string as the locale parameter to use the OS settings with michael@0: * the preferred date and time formatting given by the user. michael@0: * michael@0: * Pass a locale code as described in nsILocale as the locale parameter michael@0: * (e.g. en-US) to use a specific locale. If the given locale is not michael@0: * available, a fallback will be used. michael@0: * michael@0: * NOTE: The output of this method depends on the operating system and user michael@0: * settings. Even if you pass a locale code as the first parameter, there michael@0: * are no guarantees about which locale and exact format the returned value michael@0: * uses. Even if you know the locale, the format might be customized by the michael@0: * user. Therefore you should not use the returned values in contexts where michael@0: * you depend on any specific format or language. michael@0: * michael@0: * @param locale michael@0: * Locale code of locale used to format the date or an empty string michael@0: * to follow user preference. michael@0: * @param dateFormatSelector michael@0: * Indicate which format should preferably be used for the date. michael@0: * Use one of the dateFormat* constants. michael@0: * @param timeFormatSelector michael@0: * Indicate which format should preferably be used for the time. michael@0: * Use one of the timeFormat* constants. michael@0: * @param year, month, day, hour, minute and second michael@0: * The date and time to be formatted, given in the computer's local michael@0: * time zone. michael@0: * @return The date and time formatted as human readable text according to michael@0: * user preferences or the given locale. michael@0: */ michael@0: wstring FormatDateTime(in wstring locale, michael@0: in long dateFormatSelector, michael@0: in long timeFormatSelector, michael@0: in long year, michael@0: in long month, michael@0: in long day, michael@0: in long hour, michael@0: in long minute, michael@0: in long second); michael@0: michael@0: /** michael@0: * Format the given date in a human readable format. michael@0: * michael@0: * See FormatDateTime for details. michael@0: */ michael@0: wstring FormatDate(in wstring locale, michael@0: in long dateFormatSelector, michael@0: in long year, michael@0: in long month, michael@0: in long day); michael@0: michael@0: /** michael@0: * Format the given time in a human readable format. michael@0: * michael@0: * See FormatDateTime for details. michael@0: */ michael@0: wstring FormatTime(in wstring locale, michael@0: in long timeFormatSelector, michael@0: in long hour, michael@0: in long minute, michael@0: in long second); michael@0: };