PlainDate.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  5. * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <AK/Types.h>
  11. #include <LibJS/Runtime/Completion.h>
  12. #include <LibJS/Runtime/Object.h>
  13. #include <LibJS/Runtime/Temporal/AbstractOperations.h>
  14. #include <LibJS/Runtime/Temporal/ISORecords.h>
  15. namespace JS::Temporal {
  16. class PlainDate final : public Object {
  17. JS_OBJECT(PlainDate, Object);
  18. GC_DECLARE_ALLOCATOR(PlainDate);
  19. public:
  20. virtual ~PlainDate() override = default;
  21. [[nodiscard]] ISODate iso_date() const { return m_iso_date; }
  22. [[nodiscard]] String const& calendar() const { return m_calendar; }
  23. private:
  24. PlainDate(ISODate, String calendar, Object& prototype);
  25. ISODate m_iso_date; // [[ISODate]]
  26. String m_calendar; // [[Calendar]]
  27. };
  28. ISODate create_iso_date_record(double year, double month, double day);
  29. ThrowCompletionOr<GC::Ref<PlainDate>> to_temporal_date(VM& vm, Value item, Value options = js_undefined());
  30. ThrowCompletionOr<GC::Ref<PlainDate>> create_temporal_date(VM&, ISODate, String calendar, GC::Ptr<FunctionObject> new_target = {});
  31. bool iso_date_surpasses(i8 sign, double year1, double month1, double day1, ISODate iso_date2);
  32. ThrowCompletionOr<ISODate> regulate_iso_date(VM& vm, double year, double month, double day, Overflow overflow);
  33. bool is_valid_iso_date(double year, double month, double day);
  34. ISODate balance_iso_date(double year, double month, double day);
  35. String pad_iso_year(i32 year);
  36. String temporal_date_to_string(PlainDate const&, ShowCalendar);
  37. bool iso_date_within_limits(ISODate);
  38. i8 compare_iso_date(ISODate, ISODate);
  39. ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_date(VM&, DurationOperation, PlainDate const&, Value other, Value options);
  40. ThrowCompletionOr<GC::Ref<PlainDate>> add_duration_to_date(VM&, ArithmeticOperation, PlainDate const&, Value temporal_duration_like, Value options);
  41. }