1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00
ladybird/Userland/Libraries/LibLocale/RelativeTimeFormat.h
Timothy Flynn 7f9ccd39f5 LibJS+LibLocale: Replace relative time formatting with ICU
This uses ICU for all of the Intl.RelativeTimeFormat prototypes, which
lets us remove all data from our relative-time format generator.
2024-06-15 06:57:16 +02:00

57 lines
1.2 KiB
C++

/*
* Copyright (c) 2022-2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullOwnPtr.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibLocale/Forward.h>
namespace Locale {
// 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,
};
Optional<TimeUnit> time_unit_from_string(StringView);
StringView time_unit_to_string(TimeUnit);
enum class NumericDisplay {
Always,
Auto,
};
NumericDisplay numeric_display_from_string(StringView);
StringView numeric_display_to_string(NumericDisplay);
class RelativeTimeFormat {
public:
static NonnullOwnPtr<RelativeTimeFormat> create(StringView locale, Style style);
virtual ~RelativeTimeFormat() = default;
struct Partition {
StringView type;
String value;
StringView unit;
};
virtual String format(double, TimeUnit, NumericDisplay) const = 0;
virtual Vector<Partition> format_to_parts(double, TimeUnit, NumericDisplay) const = 0;
protected:
RelativeTimeFormat() = default;
};
}