v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-date-time-format.h
Go to the documentation of this file.
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_OBJECTS_JS_DATE_TIME_FORMAT_H_
6#define V8_OBJECTS_JS_DATE_TIME_FORMAT_H_
7
8#ifndef V8_INTL_SUPPORT
9#error Internationalization is expected to be enabled.
10#endif // V8_INTL_SUPPORT
11
12#include <set>
13#include <string>
14
15#include "src/base/bit-field.h"
18#include "src/objects/managed.h"
19#include "unicode/uversion.h"
20
21// Has to be the last include (doesn't have include guards):
23
24namespace U_ICU_NAMESPACE {
25class DateIntervalFormat;
26class Locale;
27class SimpleDateFormat;
28class TimeZone;
29} // namespace U_ICU_NAMESPACE
30
31namespace v8 {
32namespace internal {
33
34#include "torque-generated/src/objects/js-date-time-format-tq.inc"
35
37 : public TorqueGeneratedJSDateTimeFormat<JSDateTimeFormat, JSObject> {
38 public:
39 // ecma-402/#sec-todatetimeoptions
40 enum class RequiredOption { kDate, kTime, kAny };
41 enum class DefaultsOption { kDate, kTime, kAll };
42
44 Isolate* isolate, DirectHandle<Map> map, DirectHandle<Object> locales,
45 DirectHandle<Object> options, const char* service);
46
50 DirectHandle<Object> options, RequiredOption required,
51 DefaultsOption defaults, const char* service);
52
54 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format);
55
57 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format);
58
60 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format);
61
62 // ecma402/#sec-unwrapdatetimeformat
64 UnwrapDateTimeFormat(Isolate* isolate, Handle<JSReceiver> format_holder);
65
66 // ecma402/#sec-datetime-format-functions
67 // DateTime Format Functions
69 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
70 DirectHandle<Object> date, const char* method_name);
71
72 // ecma402/#sec-Intl.DateTimeFormat.prototype.formatToParts
74 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
75 DirectHandle<Object> x, bool output_source, const char* method_name);
76
77 // ecma402/#sec-intl.datetimeformat.prototype.formatRange
79 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
80 DirectHandle<Object> x_date_value, DirectHandle<Object> y_date_value,
81 const char* method_name);
82
83 // ecma402/sec-Intl.DateTimeFormat.prototype.formatRangeToParts
85 Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
86 DirectHandle<Object> x_date_value, DirectHandle<Object> y_date_value,
87 const char* method_name);
88
91 DirectHandle<Object> options, RequiredOption required,
92 DefaultsOption defaults, const char* method_name);
93
94 // Function to support Temporal
96 Isolate* isolate, DirectHandle<JSReceiver> temporal,
98 const char* method_name);
99
100 V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
101
103 const icu::TimeZone& tz);
105 Isolate* isolate, const icu::UnicodeString& id);
106
107 std::unique_ptr<icu::TimeZone> static CreateTimeZone(
109
110 V8_EXPORT_PRIVATE static std::string CanonicalizeTimeZoneID(
111 const std::string& input);
112
114
115 // ecma-402/#sec-properties-of-intl-datetimeformat-instances
117
118 // enum for "hourCycle" option.
119 enum class HourCycle { kUndefined, kH11, kH12, kH23, kH24 };
120
122 inline HourCycle hour_cycle() const;
123
125 inline DateTimeStyle date_style() const;
126
128 inline DateTimeStyle time_style() const;
129
130 // Bit positions in |flags|.
131 DEFINE_TORQUE_GENERATED_JS_DATE_TIME_FORMAT_FLAGS()
132
133 static_assert(HourCycleBits::is_valid(HourCycle::kUndefined));
134 static_assert(HourCycleBits::is_valid(HourCycle::kH11));
135 static_assert(HourCycleBits::is_valid(HourCycle::kH12));
136 static_assert(HourCycleBits::is_valid(HourCycle::kH23));
137 static_assert(HourCycleBits::is_valid(HourCycle::kH24));
138
139 static_assert(DateStyleBits::is_valid(DateTimeStyle::kUndefined));
140 static_assert(DateStyleBits::is_valid(DateTimeStyle::kFull));
141 static_assert(DateStyleBits::is_valid(DateTimeStyle::kLong));
142 static_assert(DateStyleBits::is_valid(DateTimeStyle::kMedium));
143 static_assert(DateStyleBits::is_valid(DateTimeStyle::kShort));
144
145 static_assert(TimeStyleBits::is_valid(DateTimeStyle::kUndefined));
146 static_assert(TimeStyleBits::is_valid(DateTimeStyle::kFull));
147 static_assert(TimeStyleBits::is_valid(DateTimeStyle::kLong));
148 static_assert(TimeStyleBits::is_valid(DateTimeStyle::kMedium));
149 static_assert(TimeStyleBits::is_valid(DateTimeStyle::kShort));
150
151 DECL_ACCESSORS(icu_locale, Tagged<Managed<icu::Locale>>)
152 DECL_ACCESSORS(icu_simple_date_format, Tagged<Managed<icu::SimpleDateFormat>>)
153 DECL_ACCESSORS(icu_date_interval_format,
154 Tagged<Managed<icu::DateIntervalFormat>>)
155
157
159};
160
161} // namespace internal
162} // namespace v8
163
164#include "src/objects/object-macros-undef.h"
165
166#endif // V8_OBJECTS_JS_DATE_TIME_FORMAT_H_
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSDateTimeFormat > UnwrapDateTimeFormat(Isolate *isolate, Handle< JSReceiver > format_holder)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > FormatRange(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format, DirectHandle< Object > x_date_value, DirectHandle< Object > y_date_value, const char *method_name)
static DirectHandle< Object > TimeZoneId(Isolate *isolate, const icu::TimeZone &tz)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > DateTimeFormat(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format, DirectHandle< Object > date, const char *method_name)
void set_date_style(DateTimeStyle date_style)
void set_hour_cycle(HourCycle hour_cycle)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSObject > ResolvedOptions(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSArray > FormatRangeToParts(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format, DirectHandle< Object > x_date_value, DirectHandle< Object > y_date_value, const char *method_name)
static V8_EXPORT_PRIVATE const std::set< std::string > & GetAvailableLocales()
static V8_WARN_UNUSED_RESULT MaybeHandle< String > TimeZoneIdToString(Isolate *isolate, const icu::UnicodeString &id)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > ToLocaleDateTime(Isolate *isolate, DirectHandle< Object > date, DirectHandle< Object > locales, DirectHandle< Object > options, RequiredOption required, DefaultsOption defaults, const char *method_name)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSArray > FormatToParts(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format, DirectHandle< Object > x, bool output_source, const char *method_name)
static V8_WARN_UNUSED_RESULT DirectHandle< String > Calendar(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format)
static std::unique_ptr< icu::TimeZone > CreateTimeZone(Isolate *isolate, DirectHandle< String > time_zone)
static V8_WARN_UNUSED_RESULT DirectHandle< Object > TimeZone(Isolate *isolate, DirectHandle< JSDateTimeFormat > date_time_format)
void set_time_style(DateTimeStyle time_style)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSDateTimeFormat > CreateDateTimeFormat(Isolate *isolate, DirectHandle< Map > map, DirectHandle< Object > locales, DirectHandle< Object > options, RequiredOption required, DefaultsOption defaults, const char *service)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > TemporalToLocaleString(Isolate *isolate, DirectHandle< JSReceiver > temporal, DirectHandle< Object > locales, DirectHandle< Object > options, const char *method_name)
static V8_EXPORT_PRIVATE std::string CanonicalizeTimeZoneID(const std::string &input)
Handle< String > HourCycleAsString(Isolate *isolate) const
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSDateTimeFormat > New(Isolate *isolate, DirectHandle< Map > map, DirectHandle< Object > locales, DirectHandle< Object > options, const char *service)
TimeZoneRecord time_zone
DateRecord date
int x
#define DECL_ACCESSORS(name,...)
#define DECL_PRINTER(Name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671