DateTimeFormat.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Intl/DateTimeFormat.h>
  7. namespace JS::Intl {
  8. Vector<StringView> const& DateTimeFormat::relevant_extension_keys()
  9. {
  10. // 11.3.3 Internal slots, https://tc39.es/ecma402/#sec-intl.datetimeformat-internal-slots
  11. // The value of the [[RelevantExtensionKeys]] internal slot is « "ca", "hc", "nu" ».
  12. static Vector<StringView> relevant_extension_keys { "ca"sv, "hc"sv, "nu"sv };
  13. return relevant_extension_keys;
  14. }
  15. // 11 DateTimeFormat Objects, https://tc39.es/ecma402/#datetimeformat-objects
  16. DateTimeFormat::DateTimeFormat(Object& prototype)
  17. : Object(prototype)
  18. {
  19. }
  20. DateTimeFormat::Style DateTimeFormat::style_from_string(StringView style)
  21. {
  22. if (style == "full"sv)
  23. return Style::Full;
  24. if (style == "long"sv)
  25. return Style::Long;
  26. if (style == "medium"sv)
  27. return Style::Medium;
  28. if (style == "short"sv)
  29. return Style::Short;
  30. VERIFY_NOT_REACHED();
  31. }
  32. StringView DateTimeFormat::style_to_string(Style style)
  33. {
  34. switch (style) {
  35. case Style::Full:
  36. return "full"sv;
  37. case Style::Long:
  38. return "long"sv;
  39. case Style::Medium:
  40. return "medium"sv;
  41. case Style::Short:
  42. return "short"sv;
  43. default:
  44. VERIFY_NOT_REACHED();
  45. }
  46. }
  47. }