Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
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
using UDateFormat = void*;
19
20
namespace js {
21
22
class DateTimeFormatObject : public NativeObject {
23
public:
24
static const JSClass class_;
25
static const JSClass& protoClass_;
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
// Estimated memory use for UDateFormat.
36
static constexpr size_t EstimatedMemoryUse = 91626;
37
38
UDateFormat* getDateFormat() const {
39
const auto& slot = getFixedSlot(UDATE_FORMAT_SLOT);
40
if (slot.isUndefined()) {
41
return nullptr;
42
}
43
return static_cast<UDateFormat*>(slot.toPrivate());
44
}
45
46
void setDateFormat(UDateFormat* dateFormat) {
47
setFixedSlot(UDATE_FORMAT_SLOT, PrivateValue(dateFormat));
48
}
49
50
private:
51
static const JSClassOps classOps_;
52
static const ClassSpec classSpec_;
53
54
static void finalize(JSFreeOp* fop, JSObject* obj);
55
};
56
57
/**
58
* Returns a new instance of the standard built-in DateTimeFormat constructor.
59
* Self-hosted code cannot cache this constructor (as it does for others in
60
* Utilities.js) because it is initialized after self-hosted code is compiled.
61
*
62
* Usage: dateTimeFormat = intl_DateTimeFormat(locales, options)
63
*/
64
extern MOZ_MUST_USE bool intl_DateTimeFormat(JSContext* cx, unsigned argc,
65
JS::Value* vp);
66
67
/**
68
* Returns an array with the calendar type identifiers per Unicode
69
* Technical Standard 35, Unicode Locale Data Markup Language, for the
70
* supported calendars for the given locale. The default calendar is
71
* element 0.
72
*
73
* Usage: calendars = intl_availableCalendars(locale)
74
*/
75
extern MOZ_MUST_USE bool intl_availableCalendars(JSContext* cx, unsigned argc,
76
JS::Value* vp);
77
78
/**
79
* Returns the calendar type identifier per Unicode Technical Standard 35,
80
* Unicode Locale Data Markup Language, for the default calendar for the given
81
* locale.
82
*
83
* Usage: calendar = intl_defaultCalendar(locale)
84
*/
85
extern MOZ_MUST_USE bool intl_defaultCalendar(JSContext* cx, unsigned argc,
86
JS::Value* vp);
87
88
/**
89
* 6.4.1 IsValidTimeZoneName ( timeZone )
90
*
91
* Verifies that the given string is a valid time zone name. If it is a valid
92
* time zone name, its IANA time zone name is returned. Otherwise returns null.
93
*
94
* ES2017 Intl draft rev 4a23f407336d382ed5e3471200c690c9b020b5f3
95
*
96
* Usage: ianaTimeZone = intl_IsValidTimeZoneName(timeZone)
97
*/
98
extern MOZ_MUST_USE bool intl_IsValidTimeZoneName(JSContext* cx, unsigned argc,
99
JS::Value* vp);
100
101
/**
102
* Return the canonicalized time zone name. Canonicalization resolves link
103
* names to their target time zones.
104
*
105
* Usage: ianaTimeZone = intl_canonicalizeTimeZone(timeZone)
106
*/
107
extern MOZ_MUST_USE bool intl_canonicalizeTimeZone(JSContext* cx, unsigned argc,
108
JS::Value* vp);
109
110
/**
111
* Return the default time zone name. The time zone name is not canonicalized.
112
*
113
* Usage: icuDefaultTimeZone = intl_defaultTimeZone()
114
*/
115
extern MOZ_MUST_USE bool intl_defaultTimeZone(JSContext* cx, unsigned argc,
116
JS::Value* vp);
117
118
/**
119
* Return the raw offset from GMT in milliseconds for the default time zone.
120
*
121
* Usage: defaultTimeZoneOffset = intl_defaultTimeZoneOffset()
122
*/
123
extern MOZ_MUST_USE bool intl_defaultTimeZoneOffset(JSContext* cx,
124
unsigned argc,
125
JS::Value* vp);
126
127
/**
128
* Return true if the given string is the default time zone as returned by
129
* intl_defaultTimeZone(). Otherwise return false.
130
*
131
* Usage: isIcuDefaultTimeZone = intl_isDefaultTimeZone(icuDefaultTimeZone)
132
*/
133
extern MOZ_MUST_USE bool intl_isDefaultTimeZone(JSContext* cx, unsigned argc,
134
JS::Value* vp);
135
136
/**
137
* Return a pattern in the date-time format pattern language of Unicode
138
* Technical Standard 35, Unicode Locale Data Markup Language, for the
139
* best-fit date-time format pattern corresponding to skeleton for the
140
* given locale.
141
*
142
* Usage: pattern = intl_patternForSkeleton(locale, skeleton)
143
*/
144
extern MOZ_MUST_USE bool intl_patternForSkeleton(JSContext* cx, unsigned argc,
145
JS::Value* vp);
146
147
/**
148
* Return a pattern in the date-time format pattern language of Unicode
149
* Technical Standard 35, Unicode Locale Data Markup Language, for the
150
* best-fit date-time style for the given locale.
151
* The function takes four arguments:
152
*
153
* locale
154
* BCP47 compliant locale string
155
* dateStyle
156
* A string with values: full or long or medium or short, or `undefined`
157
* timeStyle
158
* A string with values: full or long or medium or short, or `undefined`
159
* timeZone
160
* IANA time zone name
161
*
162
* Date and time style categories map to CLDR time/date standard
163
* format patterns.
164
*
165
* For the definition of a pattern string, see LDML 4.8:
167
*
168
* If `undefined` is passed to `dateStyle` or `timeStyle`, the respective
169
* portions of the pattern will not be included in the result.
170
*
171
* Usage: pattern = intl_patternForStyle(locale, dateStyle, timeStyle, timeZone)
172
*/
173
extern MOZ_MUST_USE bool intl_patternForStyle(JSContext* cx, unsigned argc,
174
JS::Value* vp);
175
176
/**
177
* Returns a String value representing x (which must be a Number value)
178
* according to the effective locale and the formatting options of the
179
* given DateTimeFormat.
180
*
181
* Spec: ECMAScript Internationalization API Specification, 12.3.2.
182
*
183
* Usage: formatted = intl_FormatDateTime(dateTimeFormat, x, formatToParts)
184
*/
185
extern MOZ_MUST_USE bool intl_FormatDateTime(JSContext* cx, unsigned argc,
186
JS::Value* vp);
187
188
} // namespace js
189
190
#endif /* builtin_intl_DateTimeFormat_h */