14#include <fmt/format.h>
29 static constexpr std::array<LocalePatterns, 9> patterns = {{
30 {
"",
"{d:02} {b} {Y}"},
31 {
"en_US",
"{d:02} {b} {Y}"},
32 {
"ar_EG",
"{d:02} {b} {Y}"},
33 {
"zh_HANS",
"{Y}年{m}月{d}日"},
34 {
"zh_HANT",
"{Y}年{m}月{d}日"},
35 {
"hu_HU",
"{Y}. {b} {d:02}"},
36 {
"ja_JP",
"{Y}年{m}月{d}日"},
37 {
"ko_KR",
"{Y}년 {m}월 {d}일"},
38 {
"ur",
"{d:02} {b} {Y}"},
42 if (pattern.locale == locale_iso) {
53 const std::tm *ltime = std::localtime(&
time);
59 const time_t zero = 0;
60 return *std::localtime(&zero);
65 std::string_view time_format_str;
68 time_format_str =
"{H:02}:{M:02}";
71 time_format_str =
"{I}:{M:02} {p}";
74 return fmt::format(fmt::runtime(time_format_str),
75 fmt::arg(
"H", date_time.tm_hour),
76 fmt::arg(
"M", date_time.tm_min),
77 fmt::arg(
"S", date_time.tm_sec),
78 fmt::arg(
"I", (date_time.tm_hour % 12) == 0 ? 12 : (date_time.tm_hour % 12)),
99 BLI_assert(date_time.tm_mon >= 0 && date_time.tm_mon < 12);
100 const int month_index = std::clamp(date_time.tm_mon, 0, 11);
102 std::string_view date_format_str;
106 date_format_str = pattern.
date;
110 date_format_str =
"{d:02}/{m:02}/{Y}";
113 date_format_str =
"{d:02}.{m:02}.{Y}";
116 date_format_str =
"{d:02}-{m:02}-{Y}";
119 date_format_str =
"{m:02}/{d:02}/{Y}";
122 date_format_str =
"{Y}/{m:02}/{d:02}";
125 date_format_str =
"{Y}.{m:02}.{d:02}";
128 date_format_str =
"{Y}-{m:02}-{d:02}";
132 return fmt::format(fmt::runtime(date_format_str),
133 fmt::arg(
"Y", date_time.tm_year + 1900),
134 fmt::arg(
"m", date_time.tm_mon + 1),
136 fmt::arg(
"d", date_time.tm_mday));
147 bool is_today =
false;
148 bool is_yesterday =
false;
150 is_today = (date_time.tm_yday == now->tm_yday && date_time.tm_year == now->tm_year);
151 std::tm yesterday_tm = *now;
152 yesterday_tm.tm_mday--;
153 mktime(&yesterday_tm);
154 is_yesterday = (date_time.tm_yday == yesterday_tm.tm_yday &&
155 date_time.tm_year == yesterday_tm.tm_year);
158 const std::string time_s =
time(date_time, time_format);
161 return fmt::format(
"{} {}", today, time_s);
164 return fmt::format(
"{} {}", yesterday, time_s);
166 const std::string date_s =
date(date_time, locale_iso, date_format);
167 return fmt::format(
"{} {}", date_s, time_s);
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_TIME
#define CTX_IFACE_(context, msgid)
constexpr bool is_empty() const
static const LocalePatterns & get_locale_patterns(const StringRef locale_iso)
std::string time(const std::tm &date_time, TimeFormat format=TimeFormat::H24)
std::string datetime(const std::tm &date_time, StringRef locale_iso={}, DateFormat date_format=DateFormat::Default, TimeFormat time_format=TimeFormat::H24, const std::tm *now=nullptr, StringRef today={}, StringRef yesterday={})
std::tm localtime_safe(time_t time)
std::string date(const std::tm &date_time, StringRef locale_iso={}, DateFormat format=DateFormat::Default)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)