blob: 9d2671c89c24a062763beccccc8482df2c7577ed [file] [log] [blame]
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +00001/*
commit-queue@webkit.orgcc0ef6d2018-05-07 22:44:28 +00002 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family)
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000027
ysuzuki@apple.com827d8d82019-12-03 01:47:31 +000028#include "JSObject.h"
commit-queue@webkit.orgb07fa912015-12-23 21:50:47 +000029#include <unicode/udat.h>
commit-queue@webkit.orgc8f58562017-04-21 17:58:32 +000030
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000031namespace JSC {
32
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000033class JSBoundFunction;
34
ysuzuki@apple.com827d8d82019-12-03 01:47:31 +000035class IntlDateTimeFormat final : public JSNonFinalObject {
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000036public:
ysuzuki@apple.com827d8d82019-12-03 01:47:31 +000037 using Base = JSNonFinalObject;
38
39 static constexpr bool needsDestruction = true;
40
41 static void destroy(JSCell* cell)
42 {
43 static_cast<IntlDateTimeFormat*>(cell)->IntlDateTimeFormat::~IntlDateTimeFormat();
44 }
45
46 template<typename CellType, SubspaceAccess mode>
47 static IsoSubspace* subspaceFor(VM& vm)
48 {
49 return vm.intlDateTimeFormatSpace<mode>();
50 }
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000051
utatane.tea@gmail.comf77bece2016-05-15 21:11:27 +000052 static IntlDateTimeFormat* create(VM&, Structure*);
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000053 static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
54
55 DECLARE_INFO;
56
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000057 void initializeDateTimeFormat(JSGlobalObject*, JSValue locales, JSValue options);
ross.kirsling@sony.com22951d32020-05-05 18:21:32 +000058 JSValue format(JSGlobalObject*, double value) const;
59 JSValue formatToParts(JSGlobalObject*, double value) const;
60 JSObject* resolvedOptions(JSGlobalObject*) const;
commit-queue@webkit.org5db3dc42015-12-23 10:48:26 +000061
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000062 JSBoundFunction* boundFormat() const { return m_boundFormat.get(); }
63 void setBoundFormat(VM&, JSBoundFunction*);
64
ross.kirsling@sony.com02ea60d2020-04-21 06:11:07 +000065private:
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000066 IntlDateTimeFormat(VM&, Structure*);
67 void finishCreation(VM&);
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000068 static void visitChildren(JSCell*, SlotVisitor&);
69
ross.kirsling@sony.com774a7362020-04-30 03:00:35 +000070 static Vector<String> localeData(const String&, size_t);
71
rmorisset@apple.com8bf82682019-03-11 17:54:59 +000072 enum class Weekday : uint8_t { None, Narrow, Short, Long };
73 enum class Era : uint8_t { None, Narrow, Short, Long };
74 enum class Year : uint8_t { None, TwoDigit, Numeric };
75 enum class Month : uint8_t { None, TwoDigit, Numeric, Narrow, Short, Long };
76 enum class Day : uint8_t { None, TwoDigit, Numeric };
77 enum class Hour : uint8_t { None, TwoDigit, Numeric };
78 enum class Minute : uint8_t { None, TwoDigit, Numeric };
79 enum class Second : uint8_t { None, TwoDigit, Numeric };
80 enum class TimeZoneName : uint8_t { None, Short, Long };
commit-queue@webkit.org5db3dc42015-12-23 10:48:26 +000081
sukolsak@gmail.comee0d79a2016-02-22 01:55:41 +000082 struct UDateFormatDeleter {
83 void operator()(UDateFormat*) const;
84 };
85
86 void setFormatsFromPattern(const StringView&);
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000087 static ASCIILiteral weekdayString(Weekday);
88 static ASCIILiteral eraString(Era);
89 static ASCIILiteral yearString(Year);
90 static ASCIILiteral monthString(Month);
91 static ASCIILiteral dayString(Day);
92 static ASCIILiteral hourString(Hour);
93 static ASCIILiteral minuteString(Minute);
94 static ASCIILiteral secondString(Second);
95 static ASCIILiteral timeZoneNameString(TimeZoneName);
commit-queue@webkit.org5db3dc42015-12-23 10:48:26 +000096
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +000097 WriteBarrier<JSBoundFunction> m_boundFormat;
sukolsak@gmail.comee0d79a2016-02-22 01:55:41 +000098 std::unique_ptr<UDateFormat, UDateFormatDeleter> m_dateFormat;
commit-queue@webkit.org5db3dc42015-12-23 10:48:26 +000099
sukolsak@gmail.comee0d79a2016-02-22 01:55:41 +0000100 String m_locale;
101 String m_calendar;
102 String m_numberingSystem;
103 String m_timeZone;
commit-queue@webkit.orga779d0e2018-08-01 21:19:27 +0000104 String m_hourCycle;
commit-queue@webkit.org5db3dc42015-12-23 10:48:26 +0000105 Weekday m_weekday { Weekday::None };
106 Era m_era { Era::None };
107 Year m_year { Year::None };
108 Month m_month { Month::None };
109 Day m_day { Day::None };
110 Hour m_hour { Hour::None };
111 Minute m_minute { Minute::None };
112 Second m_second { Second::None };
113 TimeZoneName m_timeZoneName { TimeZoneName::None };
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +0000114};
commit-queue@webkit.org77e4cc22015-07-30 03:33:32 +0000115
116} // namespace JSC