PlainYearMonth.cpp 731 B

1234567891011121314151617181920212223242526
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Temporal/PlainYearMonth.h>
  7. namespace JS::Temporal {
  8. // 9.5.5 BalanceISOYearMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-balanceisoyearmonth
  9. ISOYearMonth balance_iso_year_month(i32 year, i32 month)
  10. {
  11. // 1. Assert: year and month are integers.
  12. // 2. Set year to year + floor((month - 1) / 12).
  13. year += (month - 1) / 12;
  14. // 3. Set month to (month − 1) modulo 12 + 1.
  15. month = (month - 1) % 12 + 1;
  16. // 4. Return the new Record { [[Year]]: year, [[Month]]: month }.
  17. return ISOYearMonth { .year = year, .month = static_cast<u8>(month) };
  18. }
  19. }