V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-date-time-format.h
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_INTL_SUPPORT
6 #error Internationalization is expected to be enabled.
7 #endif // V8_INTL_SUPPORT
8 
9 #ifndef V8_OBJECTS_JS_DATE_TIME_FORMAT_H_
10 #define V8_OBJECTS_JS_DATE_TIME_FORMAT_H_
11 
12 #include <set>
13 #include <string>
14 
15 #include "src/isolate.h"
16 #include "src/objects/intl-objects.h"
17 #include "src/objects/managed.h"
18 #include "unicode/uversion.h"
19 
20 // Has to be the last include (doesn't have include guards):
21 #include "src/objects/object-macros.h"
22 
23 namespace U_ICU_NAMESPACE {
24 class Locale;
25 class SimpleDateFormat;
26 } // namespace U_ICU_NAMESPACE
27 
28 namespace v8 {
29 namespace internal {
30 
31 class JSDateTimeFormat : public JSObject {
32  public:
33  V8_WARN_UNUSED_RESULT static MaybeHandle<JSDateTimeFormat> Initialize(
34  Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
35  Handle<Object> locales, Handle<Object> options);
36 
37  V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> ResolvedOptions(
38  Isolate* isolate, Handle<JSDateTimeFormat> date_time_format);
39 
40  // ecma402/#sec-unwrapdatetimeformat
41  V8_WARN_UNUSED_RESULT static MaybeHandle<JSDateTimeFormat>
42  UnwrapDateTimeFormat(Isolate* isolate, Handle<JSReceiver> format_holder);
43 
44  // Convert the options to ICU DateTimePatternGenerator skeleton.
45  static Maybe<std::string> OptionsToSkeleton(Isolate* isolate,
46  Handle<JSReceiver> options);
47 
48  // Return the time zone id which match ICU's expectation of title casing
49  // return empty string when error.
50  static std::string CanonicalizeTimeZoneID(Isolate* isolate,
51  const std::string& input);
52 
53  // ecma402/#sec-datetime-format-functions
54  // DateTime Format Functions
55  V8_WARN_UNUSED_RESULT static MaybeHandle<String> DateTimeFormat(
56  Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
57  Handle<Object> date);
58 
59  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> FormatToParts(
60  Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
61  double date_value);
62 
63  // ecma-402/#sec-todatetimeoptions
64  enum class RequiredOption { kDate, kTime, kAny };
65  enum class DefaultsOption { kDate, kTime, kAll };
66  V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> ToDateTimeOptions(
67  Isolate* isolate, Handle<Object> input_options, RequiredOption required,
68  DefaultsOption defaults);
69 
70  V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToLocaleDateTime(
71  Isolate* isolate, Handle<Object> date, Handle<Object> locales,
72  Handle<Object> options, RequiredOption required, DefaultsOption defaults);
73 
74  static std::set<std::string> GetAvailableLocales();
75 
76  DECL_CAST(JSDateTimeFormat)
77 
78 // Layout description.
79 #define JS_DATE_TIME_FORMAT_FIELDS(V) \
80  V(kICULocaleOffset, kTaggedSize) \
81  V(kICUSimpleDateFormatOffset, kTaggedSize) \
82  V(kBoundFormatOffset, kTaggedSize) \
83  /* Total size. */ \
84  V(kSize, 0)
85 
86  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
87  JS_DATE_TIME_FORMAT_FIELDS)
88 #undef JS_DATE_TIME_FORMAT_FIELDS
89 
90  DECL_ACCESSORS(icu_locale, Managed<icu::Locale>)
91  DECL_ACCESSORS(icu_simple_date_format, Managed<icu::SimpleDateFormat>)
92  DECL_ACCESSORS(bound_format, Object)
93 
94  DECL_PRINTER(JSDateTimeFormat)
95  DECL_VERIFIER(JSDateTimeFormat)
96 
97  private:
98  DISALLOW_IMPLICIT_CONSTRUCTORS(JSDateTimeFormat);
99 };
100 
101 } // namespace internal
102 } // namespace v8
103 
104 #include "src/objects/object-macros-undef.h"
105 
106 #endif // V8_OBJECTS_JS_DATE_TIME_FORMAT_H_
Definition: v8.h:56
Definition: libplatform.h:13