/* * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace JS::Temporal { class TimeZone final : public Object { JS_OBJECT(TimeZone, Object); public: // Needs to store values in the range -8.64 * 10^13 to 8.64 * 10^13 using OffsetType = double; explicit TimeZone(Object& prototype); virtual ~TimeZone() override = default; [[nodiscard]] String const& identifier() const { return m_identifier; } [[nodiscard]] Optional const& offset_nanoseconds() const { return m_offset_nanoseconds; } void set_identifier(String identifier) { m_identifier = move(identifier); }; void set_offset_nanoseconds(OffsetType offset_nanoseconds) { m_offset_nanoseconds = offset_nanoseconds; }; private: // 11.5 Properties of Temporal.TimeZone Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-timezone-instances String m_identifier; // [[Identifier]] Optional m_offset_nanoseconds; // [[OffsetNanoseconds]] }; bool is_valid_time_zone_name(String const& time_zone); String canonicalize_time_zone_name(String const& time_zone); String default_time_zone(); ThrowCompletionOr parse_temporal_time_zone(GlobalObject&, String const&); ThrowCompletionOr create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr); ISODateTime get_iso_parts_from_epoch(BigInt const& epoch_nanoseconds); MarkedVector get_iana_time_zone_epoch_value(GlobalObject&, StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond); i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier); BigInt* get_iana_time_zone_next_transition(GlobalObject&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier); BigInt* get_iana_time_zone_previous_transition(GlobalObject&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier); ThrowCompletionOr parse_time_zone_offset_string(GlobalObject&, String const&); String format_time_zone_offset_string(double offset_nanoseconds); String format_iso_time_zone_offset_string(double offset_nanoseconds); ThrowCompletionOr to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like); ThrowCompletionOr get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&); ThrowCompletionOr builtin_time_zone_get_offset_string_for(GlobalObject&, Value time_zone, Instant&); ThrowCompletionOr builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar); ThrowCompletionOr builtin_time_zone_get_instant_for(GlobalObject&, Value time_zone, PlainDateTime&, StringView disambiguation); ThrowCompletionOr disambiguate_possible_instants(GlobalObject&, MarkedVector const& possible_instants, Value time_zone, PlainDateTime&, StringView disambiguation); ThrowCompletionOr> get_possible_instants_for(GlobalObject&, Value time_zone, PlainDateTime&); ThrowCompletionOr time_zone_equals(GlobalObject&, Object& one, Object& two); bool is_valid_time_zone_numeric_utc_offset_syntax(String const&); }