TimeZone.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. String const& identifier() const { return m_identifier; }
  19. 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. // [[Identifier]]
  24. String m_identifier;
  25. // [[OffsetNanoseconds]]
  26. Optional<OffsetType> m_offset_nanoseconds;
  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. String parse_temporal_time_zone(GlobalObject&, String const&);
  32. TimeZone* create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject* new_target = nullptr);
  33. Optional<ISODateTime> get_iso_parts_from_epoch(BigInt const& epoch_nanoseconds);
  34. i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier);
  35. double parse_time_zone_offset_string(GlobalObject&, String const&);
  36. String format_time_zone_offset_string(double offset_nanoseconds);
  37. Object* to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like);
  38. double get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&);
  39. Optional<String> builtin_time_zone_get_offset_string_for(GlobalObject&, TimeZone&, Instant&);
  40. PlainDateTime* builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar);
  41. bool is_valid_time_zone_numeric_utc_offset_syntax(String const&);
  42. }