PlainMonthDay.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Object.h>
  8. namespace JS::Temporal {
  9. class PlainMonthDay final : public Object {
  10. JS_OBJECT(PlainMonthDay, Object);
  11. public:
  12. PlainMonthDay(u8 iso_month, u8 iso_day, i32 iso_year, Object& calendar, Object& prototype);
  13. virtual ~PlainMonthDay() override = default;
  14. [[nodiscard]] i32 iso_year() const { return m_iso_year; }
  15. [[nodiscard]] u8 iso_month() const { return m_iso_month; }
  16. [[nodiscard]] u8 iso_day() const { return m_iso_day; }
  17. [[nodiscard]] Object const& calendar() const { return m_calendar; }
  18. [[nodiscard]] Object& calendar() { return m_calendar; }
  19. private:
  20. virtual void visit_edges(Visitor&) override;
  21. // 10.4 Properties of Temporal.PlainMonthDay Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plainmonthday-instances
  22. i32 m_iso_year { 0 }; // [[ISOYear]]
  23. u8 m_iso_month { 0 }; // [[ISOMonth]]
  24. u8 m_iso_day { 0 }; // [[ISODay]]
  25. Object& m_calendar; // [[Calendar]]
  26. };
  27. struct ISOMonthDay {
  28. u8 month;
  29. u8 day;
  30. i32 reference_iso_year;
  31. };
  32. ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject&, Value item, Object const* options = nullptr);
  33. ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject&, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target = nullptr);
  34. ThrowCompletionOr<String> temporal_month_day_to_string(GlobalObject&, PlainMonthDay&, StringView show_calendar);
  35. }