2021-07-07 17:41:37 +01:00
|
|
|
|
/*
|
2023-01-26 15:48:03 +00:00
|
|
|
|
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
2021-07-11 21:04:11 +03:00
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
2021-07-07 17:41:37 +01:00
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <AK/Optional.h>
|
2021-08-31 00:15:36 +01:00
|
|
|
|
#include <AK/Variant.h>
|
2021-07-07 17:41:37 +01:00
|
|
|
|
#include <LibJS/Runtime/BigInt.h>
|
2021-09-16 22:32:37 +01:00
|
|
|
|
#include <LibJS/Runtime/Completion.h>
|
2021-07-07 17:41:37 +01:00
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
2022-05-06 19:01:15 +02:00
|
|
|
|
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
2021-07-07 17:41:37 +01:00
|
|
|
|
|
|
|
|
|
|
namespace JS::Temporal {
|
|
|
|
|
|
|
|
|
|
|
|
class Instant final : public Object {
|
|
|
|
|
|
JS_OBJECT(Instant, Object);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
virtual ~Instant() override = default;
|
|
|
|
|
|
|
2021-08-07 21:50:35 +01:00
|
|
|
|
[[nodiscard]] BigInt const& nanoseconds() const { return m_nanoseconds; }
|
2021-07-07 17:41:37 +01:00
|
|
|
|
|
|
|
|
|
|
private:
|
2022-08-28 23:51:28 +02:00
|
|
|
|
Instant(BigInt const& nanoseconds, Object& prototype);
|
|
|
|
|
|
|
2021-07-07 17:41:37 +01:00
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
|
|
|
|
|
|
|
|
// 8.4 Properties of Temporal.Instant Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-instant-instances
|
2023-02-26 16:09:02 -07:00
|
|
|
|
NonnullGCPtr<BigInt const> m_nanoseconds; // [[Nanoseconds]]
|
2021-07-07 17:41:37 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-05-06 19:28:56 +02:00
|
|
|
|
// https://tc39.es/proposal-temporal/#eqn-nsMaxInstant
|
|
|
|
|
|
// nsMaxInstant = 10^8 × nsPerDay = 8.64 × 10^21
|
|
|
|
|
|
static auto const ns_max_instant = "8640000000000000000000"_sbigint;
|
|
|
|
|
|
|
|
|
|
|
|
// https://tc39.es/proposal-temporal/#eqn-nsMinInstant
|
|
|
|
|
|
// nsMinInstant = -nsMaxInstant = -8.64 × 10^21
|
|
|
|
|
|
static auto const ns_min_instant = "-8640000000000000000000"_sbigint;
|
2021-07-07 17:41:37 +01:00
|
|
|
|
|
|
|
|
|
|
bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds);
|
2022-10-14 09:47:17 -04:00
|
|
|
|
bool is_valid_epoch_nanoseconds(Crypto::SignedBigInteger const& epoch_nanoseconds);
|
2022-08-20 08:52:42 +01:00
|
|
|
|
ThrowCompletionOr<Instant*> create_temporal_instant(VM&, BigInt const& nanoseconds, FunctionObject const* new_target = nullptr);
|
|
|
|
|
|
ThrowCompletionOr<Instant*> to_temporal_instant(VM&, Value item);
|
2023-01-26 15:46:03 +00:00
|
|
|
|
ThrowCompletionOr<BigInt*> parse_temporal_instant(VM&, StringView iso_string);
|
2021-07-11 21:18:48 +03:00
|
|
|
|
i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&);
|
2022-08-20 08:52:42 +01:00
|
|
|
|
ThrowCompletionOr<BigInt*> add_instant(VM&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
|
|
|
|
|
|
BigInt* difference_instant(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode);
|
|
|
|
|
|
BigInt* round_temporal_instant(VM&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
|
2023-01-26 15:48:03 +00:00
|
|
|
|
ThrowCompletionOr<String> temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
|
2022-08-20 08:52:42 +01:00
|
|
|
|
ThrowCompletionOr<Duration*> difference_temporal_instant(VM&, DifferenceOperation, Instant const&, Value other, Value options);
|
|
|
|
|
|
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(VM&, ArithmeticOperation, Instant const&, Value temporal_duration_like);
|
2021-07-07 17:41:37 +01:00
|
|
|
|
|
|
|
|
|
|
}
|