2021-07-11 21:04:11 +03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
2023-01-26 14:37:52 +00:00
|
|
|
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
2021-07-11 21:04:11 +03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-16 21:42:01 +01:00
|
|
|
#include <LibJS/Runtime/Completion.h>
|
2021-07-14 21:01:12 +01:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
2021-08-04 22:28:21 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
2021-08-16 18:04:58 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainMonthDay.h>
|
2021-08-16 00:35:05 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainYearMonth.h>
|
2021-07-11 21:04:11 +03:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
|
|
|
|
|
namespace JS::Temporal {
|
|
|
|
|
|
2021-07-14 21:01:12 +01:00
|
|
|
class Calendar final : public Object {
|
|
|
|
|
JS_OBJECT(Calendar, Object);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual ~Calendar() override = default;
|
|
|
|
|
|
2023-01-26 15:20:00 +00:00
|
|
|
[[nodiscard]] String const& identifier() const { return m_identifier; }
|
2021-07-14 21:01:12 +01:00
|
|
|
|
|
|
|
|
private:
|
2023-01-26 15:20:00 +00:00
|
|
|
Calendar(String identifier, Object& prototype);
|
2022-08-28 23:51:28 +02:00
|
|
|
|
2021-07-14 21:01:12 +01:00
|
|
|
// 12.5 Properties of Temporal.Calendar Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-calendar-instances
|
2023-01-26 15:20:00 +00:00
|
|
|
String m_identifier; // [[Identifier]]
|
2021-07-14 21:01:12 +01:00
|
|
|
};
|
|
|
|
|
|
2022-12-26 00:58:43 +00:00
|
|
|
// 14.2 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type
|
|
|
|
|
struct YearWeekRecord {
|
|
|
|
|
u8 week { 0 };
|
|
|
|
|
i32 year { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-26 14:48:42 +00:00
|
|
|
bool is_builtin_calendar(StringView identifier);
|
2023-02-05 19:02:54 +00:00
|
|
|
ReadonlySpan<StringView> available_calendars();
|
2023-01-26 15:20:00 +00:00
|
|
|
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM&, String const& identifier, FunctionObject const* new_target = nullptr);
|
2023-01-26 15:22:31 +00:00
|
|
|
ThrowCompletionOr<Calendar*> get_builtin_calendar(VM&, String const& identifier);
|
2022-08-20 08:52:42 +01:00
|
|
|
Calendar* get_iso8601_calendar(VM&);
|
2023-01-26 14:37:52 +00:00
|
|
|
ThrowCompletionOr<Vector<String>> calendar_fields(VM&, Object& calendar, Vector<StringView> const& field_names);
|
2022-08-20 08:52:42 +01:00
|
|
|
ThrowCompletionOr<Object*> calendar_merge_fields(VM&, Object& calendar, Object& fields, Object& additional_fields);
|
|
|
|
|
ThrowCompletionOr<PlainDate*> calendar_date_add(VM&, Object& calendar, Value date, Duration&, Object* options = nullptr, FunctionObject* date_add = nullptr);
|
|
|
|
|
ThrowCompletionOr<Duration*> calendar_date_until(VM&, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until = nullptr);
|
|
|
|
|
ThrowCompletionOr<double> calendar_year(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<double> calendar_month(VM&, Object& calendar, Object& date_like);
|
2023-01-26 15:23:15 +00:00
|
|
|
ThrowCompletionOr<String> calendar_month_code(VM&, Object& calendar, Object& date_like);
|
2022-08-20 08:52:42 +01:00
|
|
|
ThrowCompletionOr<double> calendar_day(VM&, Object& calendar, Object& date_like);
|
2023-01-05 03:32:04 +01:00
|
|
|
ThrowCompletionOr<double> calendar_day_of_week(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<double> calendar_day_of_year(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<double> calendar_week_of_year(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<double> calendar_year_of_week(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<double> calendar_days_in_week(VM&, Object& calendar, Object& date_like);
|
2022-12-30 05:05:46 +01:00
|
|
|
ThrowCompletionOr<double> calendar_days_in_month(VM&, Object& calendar, Object& date_like);
|
2023-01-05 03:32:04 +01:00
|
|
|
ThrowCompletionOr<double> calendar_days_in_year(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<double> calendar_months_in_year(VM&, Object& calendar, Object& date_like);
|
2022-08-20 08:52:42 +01:00
|
|
|
ThrowCompletionOr<Value> calendar_in_leap_year(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<Value> calendar_era(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<Value> calendar_era_year(VM&, Object& calendar, Object& date_like);
|
|
|
|
|
ThrowCompletionOr<Object*> to_temporal_calendar(VM&, Value);
|
|
|
|
|
ThrowCompletionOr<Object*> to_temporal_calendar_with_iso_default(VM&, Value);
|
|
|
|
|
ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(VM&, Object&);
|
|
|
|
|
ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
|
|
|
|
|
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
|
|
|
|
|
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
|
2023-01-26 15:24:16 +00:00
|
|
|
ThrowCompletionOr<String> maybe_format_calendar_annotation(VM&, Object const* calendar_object, StringView show_calendar);
|
2023-01-26 15:27:53 +00:00
|
|
|
ThrowCompletionOr<String> format_calendar_annotation(VM&, StringView id, StringView show_calendar);
|
2022-08-20 08:52:42 +01:00
|
|
|
ThrowCompletionOr<bool> calendar_equals(VM&, Object& one, Object& two);
|
|
|
|
|
ThrowCompletionOr<Object*> consolidate_calendars(VM&, Object& one, Object& two);
|
2021-07-26 16:48:47 +03:00
|
|
|
u8 iso_days_in_month(i32 year, u8 month);
|
2022-12-26 00:58:43 +00:00
|
|
|
YearWeekRecord to_iso_week_of_year(i32 year, u8 month, u8 day);
|
2023-01-26 15:31:44 +00:00
|
|
|
ThrowCompletionOr<String> iso_month_code(VM&, u8 month);
|
2022-08-20 08:52:42 +01:00
|
|
|
ThrowCompletionOr<double> resolve_iso_month(VM&, Object const& fields);
|
|
|
|
|
ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM&, Object const& fields, Object const& options);
|
|
|
|
|
ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM&, Object const& fields, Object const& options);
|
|
|
|
|
ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM&, Object const& fields, Object const& options);
|
|
|
|
|
ThrowCompletionOr<Object*> default_merge_calendar_fields(VM&, Object const& fields, Object const& additional_fields);
|
2022-08-25 22:28:11 +01:00
|
|
|
u16 to_iso_day_of_year(i32 year, u8 month, u8 day);
|
|
|
|
|
u8 to_iso_day_of_week(i32 year, u8 month, u8 day);
|
2021-07-11 21:04:11 +03:00
|
|
|
|
|
|
|
|
}
|