aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-06-08 22:00:30 +0300
committerlevlam <levlam@telegram.org>2026-06-08 22:00:30 +0300
commit161b16310a6704500482a74e6d45dcbe6f2f20af (patch)
tree62eb7d8ac7bdc89387a1821b7da43d02873c6324
parentc9912c868a7edb2c7d9763eb36b40921b0830225 (diff)
Add and use Client::get_date_time_formatting_type.
-rw-r--r--telegram-bot-api/Client.cpp71
-rw-r--r--telegram-bot-api/Client.h2
2 files changed, 36 insertions, 37 deletions
diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp
index 501b420..f7e31e6 100644
--- a/telegram-bot-api/Client.cpp
+++ b/telegram-bot-api/Client.cpp
@@ -11254,43 +11254,7 @@ td::Result<td_api::object_ptr<td_api::TextEntityType>> Client::get_text_entity_t
if (type == "date_time") {
TRY_RESULT(unix_time, object.get_required_int_field("unix_time"));
TRY_RESULT(format, object.get_optional_string_field("date_time_format"));
- bool is_invalid = false;
- auto formatting_type = [&format, &is_invalid]() -> object_ptr<td_api::DateTimeFormattingType> {
- if (format.empty()) {
- return nullptr;
- }
- if (format == "r" || format == "R") {
- return make_object<td_api::dateTimeFormattingTypeRelative>();
- }
- auto result = make_object<td_api::dateTimeFormattingTypeAbsolute>();
- for (auto c : format) {
- switch (c) {
- case 't':
- result->time_precision_ = make_object<td_api::dateTimePartPrecisionShort>();
- break;
- case 'T':
- result->time_precision_ = make_object<td_api::dateTimePartPrecisionLong>();
- break;
- case 'd':
- result->date_precision_ = make_object<td_api::dateTimePartPrecisionShort>();
- break;
- case 'D':
- result->date_precision_ = make_object<td_api::dateTimePartPrecisionLong>();
- break;
- case 'w':
- case 'W':
- result->show_day_of_week_ = true;
- break;
- default:
- is_invalid = true;
- break;
- }
- }
- return std::move(result);
- }();
- if (is_invalid) {
- return td::Status::Error(400, "Invalid date-time format specified");
- }
+ TRY_RESULT(formatting_type, get_date_time_formatting_type(format));
return make_object<td_api::textEntityTypeDateTime>(unix_time, std::move(formatting_type));
}
if (type == "mention" || type == "hashtag" || type == "cashtag" || type == "bot_command" || type == "url" ||
@@ -18550,6 +18514,39 @@ td::string Client::get_date_time_format(const object_ptr<td_api::DateTimeFormatt
}
}
+td::Result<td_api::object_ptr<td_api::DateTimeFormattingType>> Client::get_date_time_formatting_type(td::Slice format) {
+ if (format.empty()) {
+ return nullptr;
+ }
+ if (format == "r" || format == "R") {
+ return make_object<td_api::dateTimeFormattingTypeRelative>();
+ }
+ auto result = make_object<td_api::dateTimeFormattingTypeAbsolute>();
+ for (auto c : format) {
+ switch (c) {
+ case 't':
+ result->time_precision_ = make_object<td_api::dateTimePartPrecisionShort>();
+ break;
+ case 'T':
+ result->time_precision_ = make_object<td_api::dateTimePartPrecisionLong>();
+ break;
+ case 'd':
+ result->date_precision_ = make_object<td_api::dateTimePartPrecisionShort>();
+ break;
+ case 'D':
+ result->date_precision_ = make_object<td_api::dateTimePartPrecisionLong>();
+ break;
+ case 'w':
+ case 'W':
+ result->show_day_of_week_ = true;
+ break;
+ default:
+ return td::Status::Error(400, "Invalid date-time format specified");
+ }
+ }
+ return std::move(result);
+}
+
td::string Client::get_passport_element_type(int32 id) {
switch (id) {
case td_api::passportElementTypePersonalDetails::ID:
diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h
index 23bb9d8..6d789cb 100644
--- a/telegram-bot-api/Client.h
+++ b/telegram-bot-api/Client.h
@@ -1460,6 +1460,8 @@ class Client final : public WebhookActor::Callback {
static td::string get_date_time_format(const object_ptr<td_api::DateTimeFormattingType> &formatting_type);
+ static td::Result<object_ptr<td_api::DateTimeFormattingType>> get_date_time_formatting_type(td::Slice format);
+
static td::string get_passport_element_type(int32 id);
static object_ptr<td_api::PassportElementType> get_passport_element_type(td::Slice type);