TimeZone.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <LibJS/Heap/MarkedVector.h>
  9. #include <LibJS/Runtime/Object.h>
  10. #include <LibJS/Runtime/Temporal/AbstractOperations.h>
  11. namespace JS::Temporal {
  12. class TimeZone final : public Object {
  13. JS_OBJECT(TimeZone, Object);
  14. public:
  15. // Needs to store values in the range -8.64 * 10^13 to 8.64 * 10^13
  16. using OffsetType = double;
  17. virtual ~TimeZone() override = default;
  18. [[nodiscard]] String const& identifier() const { return m_identifier; }
  19. [[nodiscard]] Optional<OffsetType> const& offset_nanoseconds() const { return m_offset_nanoseconds; }
  20. void set_identifier(String identifier) { m_identifier = move(identifier); };
  21. void set_offset_nanoseconds(OffsetType offset_nanoseconds) { m_offset_nanoseconds = offset_nanoseconds; };
  22. private:
  23. explicit TimeZone(Object& prototype);
  24. // 11.5 Properties of Temporal.TimeZone Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-timezone-instances
  25. String m_identifier; // [[Identifier]]
  26. Optional<OffsetType> m_offset_nanoseconds; // [[OffsetNanoseconds]]
  27. };
  28. bool is_available_time_zone_name(StringView time_zone);
  29. ThrowCompletionOr<String> canonicalize_time_zone_name(VM&, StringView time_zone);
  30. ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM&, StringView identifier, FunctionObject const* new_target = nullptr);
  31. ISODateTime get_iso_parts_from_epoch(VM&, Crypto::SignedBigInteger const& epoch_nanoseconds);
  32. BigInt* get_named_time_zone_next_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
  33. BigInt* get_named_time_zone_previous_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
  34. ThrowCompletionOr<String> format_time_zone_offset_string(VM&, double offset_nanoseconds);
  35. ThrowCompletionOr<String> format_iso_time_zone_offset_string(VM&, double offset_nanoseconds);
  36. ThrowCompletionOr<Object*> to_temporal_time_zone(VM&, Value temporal_time_zone_like);
  37. ThrowCompletionOr<double> get_offset_nanoseconds_for(VM&, Value time_zone, Instant&);
  38. ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM&, Value time_zone, Instant&);
  39. ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM&, Value time_zone, Instant&, Object& calendar);
  40. ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(VM&, Value time_zone, PlainDateTime&, StringView disambiguation);
  41. ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM&, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime&, StringView disambiguation);
  42. ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM&, Value time_zone, PlainDateTime&);
  43. ThrowCompletionOr<bool> time_zone_equals(VM&, Object& one, Object& two);
  44. }