TimeZone.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2021, 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/Runtime/Object.h>
  9. #include <LibJS/Runtime/Temporal/AbstractOperations.h>
  10. namespace JS::Temporal {
  11. class TimeZone final : public Object {
  12. JS_OBJECT(TimeZone, Object);
  13. public:
  14. // Needs to store values in the range -8.64 * 10^13 to 8.64 * 10^13
  15. using OffsetType = double;
  16. TimeZone(String identifier, Object& prototype);
  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_offset_nanoseconds(OffsetType offset_nanoseconds) { m_offset_nanoseconds = offset_nanoseconds; };
  21. private:
  22. // 11.5 Properties of Temporal.TimeZone Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-timezone-instances
  23. String m_identifier; // [[Identifier]]
  24. Optional<OffsetType> m_offset_nanoseconds; // [[OffsetNanoseconds]]
  25. };
  26. bool is_valid_time_zone_name(String const& time_zone);
  27. String canonicalize_time_zone_name(String const& time_zone);
  28. String default_time_zone();
  29. ThrowCompletionOr<String> parse_temporal_time_zone(GlobalObject&, String const&);
  30. ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
  31. ISODateTime get_iso_parts_from_epoch(BigInt const& epoch_nanoseconds);
  32. i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier);
  33. ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject&, String const&);
  34. String format_time_zone_offset_string(double offset_nanoseconds);
  35. ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like);
  36. ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&);
  37. ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject&, Value time_zone, Instant&);
  38. ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar);
  39. bool is_valid_time_zone_numeric_utc_offset_syntax(String const&);
  40. }