Calendar.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibJS/Runtime/Object.h>
  9. #include <LibJS/Runtime/Temporal/PlainDate.h>
  10. #include <LibJS/Runtime/Temporal/PlainMonthDay.h>
  11. #include <LibJS/Runtime/Temporal/PlainYearMonth.h>
  12. #include <LibJS/Runtime/Value.h>
  13. namespace JS::Temporal {
  14. class Calendar final : public Object {
  15. JS_OBJECT(Calendar, Object);
  16. public:
  17. Calendar(String identifier, Object& prototype);
  18. virtual ~Calendar() override = default;
  19. [[nodiscard]] String const& identifier() const { return m_identifier; }
  20. private:
  21. // 12.5 Properties of Temporal.Calendar Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-calendar-instances
  22. String m_identifier; // [[Identifier]]
  23. };
  24. Calendar* create_temporal_calendar(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
  25. bool is_builtin_calendar(String const& identifier);
  26. Calendar* get_builtin_calendar(GlobalObject&, String const& identifier);
  27. Calendar* get_iso8601_calendar(GlobalObject&);
  28. Vector<String> calendar_fields(GlobalObject&, Object& calendar, Vector<StringView> const& field_names);
  29. double calendar_year(GlobalObject&, Object& calendar, Object& date_like);
  30. double calendar_month(GlobalObject&, Object& calendar, Object& date_like);
  31. String calendar_month_code(GlobalObject&, Object& calendar, Object& date_like);
  32. double calendar_day(GlobalObject&, Object& calendar, Object& date_like);
  33. Value calendar_day_of_week(GlobalObject&, Object& calendar, Object& date_like);
  34. Value calendar_day_of_year(GlobalObject&, Object& calendar, Object& date_like);
  35. Value calendar_week_of_year(GlobalObject&, Object& calendar, Object& date_like);
  36. Value calendar_days_in_week(GlobalObject&, Object& calendar, Object& date_like);
  37. Value calendar_days_in_month(GlobalObject&, Object& calendar, Object& date_like);
  38. Value calendar_days_in_year(GlobalObject&, Object& calendar, Object& date_like);
  39. Value calendar_months_in_year(GlobalObject&, Object& calendar, Object& date_like);
  40. Value calendar_in_leap_year(GlobalObject&, Object& calendar, Object& date_like);
  41. Value calendar_era(GlobalObject&, Object& calendar, Object& date_like);
  42. Value calendar_era_year(GlobalObject&, Object& calendar, Object& date_like);
  43. Object* to_temporal_calendar(GlobalObject&, Value);
  44. Object* to_temporal_calendar_with_iso_default(GlobalObject&, Value);
  45. Object* get_temporal_calendar_with_iso_default(GlobalObject&, Object&);
  46. PlainDate* date_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const& options);
  47. PlainYearMonth* year_month_from_fields(GlobalObject&, Object& calendar, Object const& fields, Object const* options = nullptr);
  48. PlainMonthDay* month_day_from_fields(GlobalObject& global_object, Object& calendar, Object const& fields, Object const* options = nullptr);
  49. String format_calendar_annotation(StringView id, StringView show_calendar);
  50. bool calendar_equals(GlobalObject&, Object& one, Object& two);
  51. Object* consolidate_calendars(GlobalObject&, Object& one, Object& two);
  52. bool is_iso_leap_year(i32 year);
  53. u16 iso_days_in_year(i32 year);
  54. u8 iso_days_in_month(i32 year, u8 month);
  55. u8 to_iso_day_of_week(i32 year, u8 month, u8 day);
  56. u16 to_iso_day_of_year(i32 year, u8 month, u8 day);
  57. u8 to_iso_week_of_year(i32 year, u8 month, u8 day);
  58. String build_iso_month_code(u8 month);
  59. double resolve_iso_month(GlobalObject&, Object const& fields);
  60. Optional<ISODate> iso_date_from_fields(GlobalObject&, Object const& fields, Object const& options);
  61. Optional<ISOYearMonth> iso_year_month_from_fields(GlobalObject&, Object const& fields, Object const& options);
  62. Optional<ISOMonthDay> iso_month_day_from_fields(GlobalObject&, Object const& fields, Object const& options);
  63. i32 iso_year(Object& temporal_object);
  64. u8 iso_month(Object& temporal_object);
  65. String iso_month_code(Object& temporal_object);
  66. u8 iso_day(Object& temporal_object);
  67. Object* default_merge_fields(GlobalObject&, Object const& fields, Object const& additional_fields);
  68. }