PlainDate.cpp 934 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Temporal/Calendar.h>
  7. #include <LibJS/Runtime/Temporal/PlainDate.h>
  8. #include <LibJS/Runtime/Value.h>
  9. namespace JS::Temporal {
  10. // 3.5.5 IsValidISODate ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-isvalidisodate
  11. bool is_valid_iso_date(i32 year, i32 month, i32 day)
  12. {
  13. // 1. Assert: year, month, and day are integers.
  14. // 2. If month < 1 or month > 12, then
  15. if (month < 1 || month > 12) {
  16. // a. Return false.
  17. return false;
  18. }
  19. // 3. Let daysInMonth be ! ISODaysInMonth(year, month).
  20. auto days_in_month = iso_days_in_month(year, month);
  21. // 4. If day < 1 or day > daysInMonth, then
  22. if (day < 1 || day > days_in_month) {
  23. // a. Return false.
  24. return false;
  25. }
  26. // 5. Return true.
  27. return true;
  28. }
  29. }