summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-07-07 17:41:37 +0100
committerLinus Groh <mail@linusgroh.de>2021-07-07 19:00:42 +0100
commit47fb4286c7247af3faa354ceba97ac46d8bd854f (patch)
tree8204a79fbb2749e26957523156b132205e5788f6 /Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
parentd9cff591b6ce8b1cedcf70a5c9705a966f0f03d4 (diff)
downloadserenity-47fb4286c7247af3faa354ceba97ac46d8bd854f.zip
LibJS: Start implementing Temporal.Instant
Just like the initial Temporal.TimeZone commit, this patch adds the Instant object itself, its constructor and prototype (currently empty), and two required abstract operations.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/Instant.h')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Instant.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
new file mode 100644
index 0000000000..7700295d93
--- /dev/null
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Optional.h>
+#include <LibJS/Runtime/BigInt.h>
+#include <LibJS/Runtime/Object.h>
+
+namespace JS::Temporal {
+
+class Instant final : public Object {
+ JS_OBJECT(Instant, Object);
+
+public:
+ explicit Instant(BigInt& nanoseconds, Object& prototype);
+ virtual ~Instant() override = default;
+
+ BigInt const& nanoseconds() const { return m_nanoseconds; }
+
+private:
+ virtual void visit_edges(Visitor&) override;
+
+ // 8.4 Properties of Temporal.Instant Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-instant-instances
+
+ // [[Nanoseconds]]
+ BigInt& m_nanoseconds;
+};
+
+// -86400 * 10^17
+const auto INSTANT_NANOSECONDS_MIN = Crypto::SignedBigInteger::from_base(10, "-8640000000000000000000");
+// +86400 * 10^17
+const auto INSTANT_NANOSECONDS_MAX = Crypto::SignedBigInteger::from_base(10, "8640000000000000000000");
+
+bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds);
+Object* create_temporal_instant(GlobalObject&, BigInt& nanoseconds, FunctionObject* new_target = nullptr);
+
+}