Instant.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Optional.h>
  9. #include <AK/Variant.h>
  10. #include <LibJS/Runtime/BigInt.h>
  11. #include <LibJS/Runtime/Object.h>
  12. namespace JS::Temporal {
  13. class Instant final : public Object {
  14. JS_OBJECT(Instant, Object);
  15. public:
  16. Instant(BigInt& nanoseconds, Object& prototype);
  17. virtual ~Instant() override = default;
  18. [[nodiscard]] BigInt const& nanoseconds() const { return m_nanoseconds; }
  19. [[nodiscard]] BigInt& nanoseconds() { return m_nanoseconds; }
  20. private:
  21. virtual void visit_edges(Visitor&) override;
  22. // 8.4 Properties of Temporal.Instant Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-instant-instances
  23. BigInt& m_nanoseconds; // [[Nanoseconds]]
  24. };
  25. // -86400 * 10^17
  26. const auto INSTANT_NANOSECONDS_MIN = "-8640000000000000000000"_sbigint;
  27. // +86400 * 10^17
  28. const auto INSTANT_NANOSECONDS_MAX = "8640000000000000000000"_sbigint;
  29. bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds);
  30. Instant* create_temporal_instant(GlobalObject&, BigInt& nanoseconds, FunctionObject* new_target = nullptr);
  31. Instant* to_temporal_instant(GlobalObject&, Value item);
  32. BigInt* parse_temporal_instant(GlobalObject&, String const& iso_string);
  33. i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&);
  34. BigInt* add_instant(GlobalObject&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
  35. BigInt* difference_instant(GlobalObject&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode);
  36. BigInt* round_temporal_instant(GlobalObject&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
  37. Optional<String> temporal_instant_to_string(GlobalObject&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
  38. }