summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibUnicode/RelativeTimeFormat.h
blob: fdf83016bb048f80ab7138c51f3903dec671ebef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
 *
 * 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);

}