RelativeTimeFormat.h 945 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <AK/StringView.h>
  9. #include <AK/Vector.h>
  10. #include <LibUnicode/Forward.h>
  11. #include <LibUnicode/Locale.h>
  12. namespace Unicode {
  13. // These are just the subset of fields in the CLDR required for ECMA-402.
  14. enum class TimeUnit {
  15. Second,
  16. Minute,
  17. Hour,
  18. Day,
  19. Week,
  20. Month,
  21. Quarter,
  22. Year,
  23. };
  24. struct RelativeTimeFormat {
  25. enum class Plurality {
  26. Zero,
  27. One,
  28. Two,
  29. Few,
  30. Many,
  31. Other,
  32. };
  33. Plurality plurality { Plurality::Other };
  34. StringView pattern;
  35. };
  36. Optional<TimeUnit> time_unit_from_string(StringView time_unit);
  37. StringView time_unit_to_string(TimeUnit time_unit);
  38. Vector<RelativeTimeFormat> get_relative_time_format_patterns(StringView locale, TimeUnit time_unit, StringView tense_or_number, Style style);
  39. }