/* * Copyright (c) 2021, Idan Horowitz * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace JS::Temporal { class Calendar final : public Object { JS_OBJECT(Calendar, Object); public: Calendar(String identifier, Object& prototype); virtual ~Calendar() override = default; [[nodiscard]] String const& identifier() const { return m_identifier; } private: // 12.5 Properties of Temporal.Calendar Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-calendar-instances String m_identifier; // [[Identifier]] }; bool is_builtin_calendar(String const& identifier); Span available_calendars(); ThrowCompletionOr create_temporal_calendar(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr); ThrowCompletionOr get_builtin_calendar(GlobalObject&, String const& identifier); Calendar* get_iso8601_calendar(GlobalObject&); ThrowCompletionOr> calendar_fields(GlobalObject&, Object& calendar, Vector const& field_names); ThrowCompletionOr calendar_merge_fields(GlobalObject&, Object& calendar, Object& fields, Object& additional_fields); ThrowCompletionOr calendar_date_add(GlobalObject&, Object& calendar, Value date, Duration&, Object* options = nullptr, FunctionObject* date_add = nullptr); ThrowCompletionOr calendar_date_until(GlobalObject&, Object& calendar, Value one, Value two, Object& options, FunctionObject* date_until = nullptr); ThrowCompletionOr calendar_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_month(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_month_code(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_day(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_day_of_week(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_day_of_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_week_of_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_days_in_week(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_days_in_month(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_days_in_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_months_in_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_in_leap_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_era(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr calendar_era_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr to_temporal_calendar(GlobalObject&, Value); ThrowCompletionOr to_temporal_calendar_with_iso_default(GlobalObject&, Value); ThrowCompletionOr get_temporal_calendar_with_iso_default(GlobalObject&, Object&); ThrowCompletionOr calendar_date_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr); ThrowCompletionOr calendar_year_month_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr); ThrowCompletionOr calendar_month_day_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr); String format_calendar_annotation(StringView id, StringView show_calendar); ThrowCompletionOr calendar_equals(GlobalObject&, Object& one, Object& two); ThrowCompletionOr consolidate_calendars(GlobalObject&, Object& one, Object& two); bool is_iso_leap_year(i32 year); u16 iso_days_in_year(i32 year); u8 iso_days_in_month(i32 year, u8 month); u8 to_iso_day_of_week(i32 year, u8 month, u8 day); u16 to_iso_day_of_year(i32 year, u8 month, u8 day); u8 to_iso_week_of_year(i32 year, u8 month, u8 day); String build_iso_month_code(u8 month); ThrowCompletionOr resolve_iso_month(GlobalObject&, Object const& fields); ThrowCompletionOr iso_date_from_fields(GlobalObject&, Object const& fields, Object const& options); ThrowCompletionOr iso_year_month_from_fields(GlobalObject&, Object const& fields, Object const& options); ThrowCompletionOr iso_month_day_from_fields(GlobalObject&, Object const& fields, Object const& options); i32 iso_year(Object& temporal_object); u8 iso_month(Object& temporal_object); String iso_month_code(Object& temporal_object); u8 iso_day(Object& temporal_object); ThrowCompletionOr default_merge_fields(GlobalObject&, Object const& fields, Object const& additional_fields); }