TimeZone.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2021-2022, 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. explicit TimeZone(Object& prototype);
  18. virtual ~TimeZone() override = default;
  19. [[nodiscard]] String const& identifier() const { return m_identifier; }
  20. [[nodiscard]] Optional<OffsetType> const& offset_nanoseconds() const { return m_offset_nanoseconds; }
  21. void set_identifier(String identifier) { m_identifier = move(identifier); };
  22. void set_offset_nanoseconds(OffsetType offset_nanoseconds) { m_offset_nanoseconds = offset_nanoseconds; };
  23. private:
  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_valid_time_zone_name(String const& time_zone);
  29. String canonicalize_time_zone_name(String const& time_zone);
  30. String default_time_zone();
  31. ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
  32. ISODateTime get_iso_parts_from_epoch(GlobalObject&, Crypto::SignedBigInteger const& epoch_nanoseconds);
  33. MarkedVector<BigInt*> 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);
  34. i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier);
  35. BigInt* get_iana_time_zone_next_transition(GlobalObject&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier);
  36. BigInt* get_iana_time_zone_previous_transition(GlobalObject&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier);
  37. ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject&, String const&);
  38. String format_time_zone_offset_string(double offset_nanoseconds);
  39. String format_iso_time_zone_offset_string(double offset_nanoseconds);
  40. ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like);
  41. ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&);
  42. ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject&, Value time_zone, Instant&);
  43. ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar);
  44. ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(GlobalObject&, Value time_zone, PlainDateTime&, StringView disambiguation);
  45. ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject&, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime&, StringView disambiguation);
  46. ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(GlobalObject&, Value time_zone, PlainDateTime&);
  47. ThrowCompletionOr<bool> time_zone_equals(GlobalObject&, Object& one, Object& two);
  48. bool is_valid_time_zone_numeric_utc_offset_syntax(String const&);
  49. }