diff options
author | Linus Groh <mail@linusgroh.de> | 2021-07-27 00:21:16 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-27 19:51:44 +0100 |
commit | c303bbde5430c8d889853ae112d50275b57f74c5 (patch) | |
tree | 384724cadb81da7e3c237404b3d073cd4e6e1ddd /Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp | |
parent | 5512ff79f0836912f19499bf5dc59c49cbb48482 (diff) | |
download | serenity-c303bbde5430c8d889853ae112d50275b57f74c5.zip |
LibJS: Implement Temporal.Now.plainDate()
...and ten required AOs we didn't have yet:
- BalanceISODate
- BalanceISODateTime
- BalanceISOYearMonth
- BalanceTime
- BuiltinTimeZoneGetPlainDateTimeFor
- GetISOPartsFromEpoch
- GetOffsetNanosecondsFor
- ParseTemporalTimeZone
- SystemDateTime
- ToTemporalTimeZone
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp new file mode 100644 index 0000000000..330e139eaa --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibJS/Runtime/Temporal/PlainYearMonth.h> + +namespace JS::Temporal { + +// 9.5.5 BalanceISOYearMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-balanceisoyearmonth +ISOYearMonth balance_iso_year_month(i32 year, i32 month) +{ + // 1. Assert: year and month are integers. + + // 2. Set year to year + floor((month - 1) / 12). + year += (month - 1) / 12; + + // 3. Set month to (month − 1) modulo 12 + 1. + month = (month - 1) % 12 + 1; + + // 4. Return the new Record { [[Year]]: year, [[Month]]: month }. + return ISOYearMonth { .year = year, .month = static_cast<u8>(month) }; +} + +} |