summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-07-11 21:04:11 +0300
committerLinus Groh <mail@linusgroh.de>2021-07-12 19:05:17 +0100
commitb816037739e323f331f43c33a8eb808cd933c465 (patch)
tree4e18c383da4bdc24a3f7b20b587d83b95e002e31 /Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
parent141c46feda1c91f3b50948749463ecf7c380aa1a (diff)
downloadserenity-b816037739e323f331f43c33a8eb808cd933c465.zip
LibJS: Add the ToTemporalInstant Abstract Operation & its requirements
This is Abstract Operation is required for the majority of InstantConstructor's and InstantPrototype's methods. The implementation is not entirely complete, (specifically 2 of the underlying required abstract operations, ParseTemporalTimeZoneString and ParseISODateTime are missing the required lexing, and as such are TODO()-ed) but the majority of it is done.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
new file mode 100644
index 0000000000..bf18c9a5c2
--- /dev/null
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibJS/Runtime/Temporal/Calendar.h>
+#include <LibJS/Runtime/Temporal/PlainDate.h>
+#include <LibJS/Runtime/Value.h>
+
+namespace JS::Temporal {
+
+// 3.5.5 IsValidISODate ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-isvalidisodate
+bool is_valid_iso_date(i32 year, i32 month, i32 day)
+{
+ // 1. Assert: year, month, and day are integers.
+
+ // 2. If month < 1 or month > 12, then
+ if (month < 1 || month > 12) {
+ // a. Return false.
+ return false;
+ }
+
+ // 3. Let daysInMonth be ! ISODaysInMonth(year, month).
+ auto days_in_month = iso_days_in_month(year, month);
+
+ // 4. If day < 1 or day > daysInMonth, then
+ if (day < 1 || day > days_in_month) {
+ // a. Return false.
+ return false;
+ }
+
+ // 5. Return true.
+ return true;
+}
+
+}