TimeZone.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. namespace JS::Temporal {
  10. class TimeZone final : public Object {
  11. JS_OBJECT(TimeZone, Object);
  12. // Needs to store values in the range -8.64 * 10^21 to 8.64 * 10^21
  13. using OffsetType = double;
  14. public:
  15. explicit TimeZone(String identifier, Object& prototype);
  16. virtual ~TimeZone() override = default;
  17. String const& identifier() const { return m_identifier; }
  18. Optional<OffsetType> const& offset_nanoseconds() const { return m_offset_nanoseconds; }
  19. void set_offset_nanoseconds(u32 offset_nanoseconds) { m_offset_nanoseconds = offset_nanoseconds; };
  20. private:
  21. // 11.5 Properties of Temporal.TimeZone Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-timezone-instances
  22. // [[Identifier]]
  23. String m_identifier;
  24. // [[OffsetNanoseconds]]
  25. Optional<OffsetType> m_offset_nanoseconds;
  26. };
  27. bool is_valid_time_zone_name(String const& time_zone);
  28. String canonicalize_time_zone_name(String const& time_zone);
  29. String default_time_zone();
  30. Object* create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject* new_target = nullptr);
  31. }