ladybird/Userland/Libraries/LibUnicode/RelativeTimeFormat.h
Timothy Flynn 789f093b2e LibUnicode: Parse and generate relative-time format patterns
Relative-time format patterns are of one of two forms:

    * Tensed - refer to the past or the future, e.g. "N years ago" or
      "in N years".
    * Numbered - refer to a specific numeric value, e.g. "in 1 year"
      becomes "next year" and "in 0 years" becomes "this year".

In ECMA-402, tensed and numbered refer to the numeric formatting options
of "always" and "auto", respectively.
2022-01-27 21:16:44 +00:00

48 lines
945 B
C++

/*
* Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibUnicode/Forward.h>
#include <LibUnicode/Locale.h>
namespace Unicode {
// These are just the subset of fields in the CLDR required for ECMA-402.
enum class TimeUnit {
Second,
Minute,
Hour,
Day,
Week,
Month,
Quarter,
Year,
};
struct RelativeTimeFormat {
enum class Plurality {
Zero,
One,
Two,
Few,
Many,
Other,
};
Plurality plurality { Plurality::Other };
StringView pattern;
};
Optional<TimeUnit> time_unit_from_string(StringView time_unit);
StringView time_unit_to_string(TimeUnit time_unit);
Vector<RelativeTimeFormat> get_relative_time_format_patterns(StringView locale, TimeUnit time_unit, StringView tense_or_number, Style style);
}