1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 * vim: set ts=8 sts=4 et sw=4 tw=99: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef builtin_intl_DateTimeFormat_h 8 #define builtin_intl_DateTimeFormat_h 9 10 #include "mozilla/Attributes.h" 11 12 #include "builtin/intl/CommonFunctions.h" 13 #include "builtin/SelfHostingDefines.h" 14 #include "js/Class.h" 15 #include "js/RootingAPI.h" 16 #include "vm/NativeObject.h" 17 18 namespace js { 19 20 class FreeOp; 21 class GlobalObject; 22 23 class DateTimeFormatObject : public NativeObject { 24 public: 25 static const Class class_; 26 27 static constexpr uint32_t INTERNALS_SLOT = 0; 28 static constexpr uint32_t UDATE_FORMAT_SLOT = 1; 29 static constexpr uint32_t SLOT_COUNT = 2; 30 31 static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT, 32 "INTERNALS_SLOT must match self-hosting define for internals " 33 "object slot"); 34 35 private: 36 static const ClassOps classOps_; 37 38 static void finalize(FreeOp* fop, JSObject* obj); 39 }; 40 41 extern JSObject* CreateDateTimeFormatPrototype( 42 JSContext* cx, JS::Handle<JSObject*> Intl, JS::Handle<GlobalObject*> global, 43 JS::MutableHandle<JSObject*> constructor, 44 intl::DateTimeFormatOptions dtfOptions); 45 46 /** 47 * Returns a new instance of the standard built-in DateTimeFormat constructor. 48 * Self-hosted code cannot cache this constructor (as it does for others in 49 * Utilities.js) because it is initialized after self-hosted code is compiled. 50 * 51 * Usage: dateTimeFormat = intl_DateTimeFormat(locales, options) 52 */ 53 extern MOZ_MUST_USE bool intl_DateTimeFormat(JSContext* cx, unsigned argc, 54 JS::Value* vp); 55 56 /** 57 * Returns an object indicating the supported locales for date and time 58 * formatting by having a true-valued property for each such locale with the 59 * canonicalized language tag as the property name. The object has no 60 * prototype. 61 * 62 * Usage: availableLocales = intl_DateTimeFormat_availableLocales() 63 */ 64 extern MOZ_MUST_USE bool intl_DateTimeFormat_availableLocales(JSContext* cx, 65 unsigned argc, 66 JS::Value* vp); 67 68 /** 69 * Returns an array with the calendar type identifiers per Unicode 70 * Technical Standard 35, Unicode Locale Data Markup Language, for the 71 * supported calendars for the given locale. The default calendar is 72 * element 0. 73 * 74 * Usage: calendars = intl_availableCalendars(locale) 75 */ 76 extern MOZ_MUST_USE bool intl_availableCalendars(JSContext* cx, unsigned argc, 77 JS::Value* vp); 78 79 /** 80 * Returns the calendar type identifier per Unicode Technical Standard 35, 81 * Unicode Locale Data Markup Language, for the default calendar for the given 82 * locale. 83 * 84 * Usage: calendar = intl_defaultCalendar(locale) 85 */ 86 extern MOZ_MUST_USE bool intl_defaultCalendar(JSContext* cx, unsigned argc, 87 JS::Value* vp); 88 89 /** 90 * 6.4.1 IsValidTimeZoneName ( timeZone ) 91 * 92 * Verifies that the given string is a valid time zone name. If it is a valid 93 * time zone name, its IANA time zone name is returned. Otherwise returns null. 94 * 95 * ES2017 Intl draft rev 4a23f407336d382ed5e3471200c690c9b020b5f3 96 * 97 * Usage: ianaTimeZone = intl_IsValidTimeZoneName(timeZone) 98 */ 99 extern MOZ_MUST_USE bool intl_IsValidTimeZoneName(JSContext* cx, unsigned argc, 100 JS::Value* vp); 101 102 /** 103 * Return the canonicalized time zone name. Canonicalization resolves link 104 * names to their target time zones. 105 * 106 * Usage: ianaTimeZone = intl_canonicalizeTimeZone(timeZone) 107 */ 108 extern MOZ_MUST_USE bool intl_canonicalizeTimeZone(JSContext* cx, unsigned argc, 109 JS::Value* vp); 110 111 /** 112 * Return the default time zone name. The time zone name is not canonicalized. 113 * 114 * Usage: icuDefaultTimeZone = intl_defaultTimeZone() 115 */ 116 extern MOZ_MUST_USE bool intl_defaultTimeZone(JSContext* cx, unsigned argc, 117 JS::Value* vp); 118 119 /** 120 * Return the raw offset from GMT in milliseconds for the default time zone. 121 * 122 * Usage: defaultTimeZoneOffset = intl_defaultTimeZoneOffset() 123 */ 124 extern MOZ_MUST_USE bool intl_defaultTimeZoneOffset(JSContext* cx, 125 unsigned argc, 126 JS::Value* vp); 127 128 /** 129 * Return true if the given string is the default time zone as returned by 130 * intl_defaultTimeZone(). Otherwise return false. 131 * 132 * Usage: isIcuDefaultTimeZone = intl_isDefaultTimeZone(icuDefaultTimeZone) 133 */ 134 extern MOZ_MUST_USE bool intl_isDefaultTimeZone(JSContext* cx, unsigned argc, 135 JS::Value* vp); 136 137 /** 138 * Return a pattern in the date-time format pattern language of Unicode 139 * Technical Standard 35, Unicode Locale Data Markup Language, for the 140 * best-fit date-time format pattern corresponding to skeleton for the 141 * given locale. 142 * 143 * Usage: pattern = intl_patternForSkeleton(locale, skeleton) 144 */ 145 extern MOZ_MUST_USE bool intl_patternForSkeleton(JSContext* cx, unsigned argc, 146 JS::Value* vp); 147 148 /** 149 * Return a pattern in the date-time format pattern language of Unicode 150 * Technical Standard 35, Unicode Locale Data Markup Language, for the 151 * best-fit date-time style for the given locale. 152 * The function takes four arguments: 153 * 154 * locale 155 * BCP47 compliant locale string 156 * dateStyle 157 * A string with values: full or long or medium or short, or `undefined` 158 * timeStyle 159 * A string with values: full or long or medium or short, or `undefined` 160 * timeZone 161 * IANA time zone name 162 * 163 * Date and time style categories map to CLDR time/date standard 164 * format patterns. 165 * 166 * For the definition of a pattern string, see LDML 4.8: 167 * http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns 168 * 169 * If `undefined` is passed to `dateStyle` or `timeStyle`, the respective 170 * portions of the pattern will not be included in the result. 171 * 172 * Usage: pattern = intl_patternForStyle(locale, dateStyle, timeStyle, timeZone) 173 */ 174 extern MOZ_MUST_USE bool intl_patternForStyle(JSContext* cx, unsigned argc, 175 JS::Value* vp); 176 177 /** 178 * Returns a String value representing x (which must be a Number value) 179 * according to the effective locale and the formatting options of the 180 * given DateTimeFormat. 181 * 182 * Spec: ECMAScript Internationalization API Specification, 12.3.2. 183 * 184 * Usage: formatted = intl_FormatDateTime(dateTimeFormat, x, formatToParts) 185 */ 186 extern MOZ_MUST_USE bool intl_FormatDateTime(JSContext* cx, unsigned argc, 187 JS::Value* vp); 188 189 } // namespace js 190 191 #endif /* builtin_intl_DateTimeFormat_h */ 192