diff options
| author | levlam <levlam@telegram.org> | 2026-06-08 21:55:26 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-06-08 21:55:26 +0300 |
| commit | c9912c868a7edb2c7d9763eb36b40921b0830225 (patch) | |
| tree | 5c88ae8bcb8a6816ed87653d35572ba30f714894 | |
| parent | 2310208a697c294f312293f350ed5d01911efd0c (diff) | |
Add and use Client::get_date_time_format.
| -rw-r--r-- | telegram-bot-api/Client.cpp | 88 | ||||
| -rw-r--r-- | telegram-bot-api/Client.h | 2 |
2 files changed, 48 insertions, 42 deletions
diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index f85e762..501b420 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -611,48 +611,7 @@ class Client::JsonEntity final : public td::Jsonable { auto entity = static_cast<const td_api::textEntityTypeDateTime *>(entity_->type_.get()); object("type", "date_time"); object("unix_time", entity->unix_time_); - td::string format; - if (entity->formatting_type_ != nullptr) { - switch (entity->formatting_type_->get_id()) { - case td_api::dateTimeFormattingTypeRelative::ID: - format = "r"; - break; - case td_api::dateTimeFormattingTypeAbsolute::ID: { - auto abs = static_cast<const td_api::dateTimeFormattingTypeAbsolute *>(entity->formatting_type_.get()); - if (abs->show_day_of_week_) { - format += 'w'; - } - switch (abs->date_precision_->get_id()) { - case td_api::dateTimePartPrecisionNone::ID: - break; - case td_api::dateTimePartPrecisionShort::ID: - format += 'd'; - break; - case td_api::dateTimePartPrecisionLong::ID: - format += 'D'; - break; - default: - UNREACHABLE(); - } - switch (abs->time_precision_->get_id()) { - case td_api::dateTimePartPrecisionNone::ID: - break; - case td_api::dateTimePartPrecisionShort::ID: - format += 't'; - break; - case td_api::dateTimePartPrecisionLong::ID: - format += 'T'; - break; - default: - UNREACHABLE(); - } - break; - } - default: - UNREACHABLE(); - } - } - object("date_time_format", format); + object("date_time_format", get_date_time_format(entity->formatting_type_)); break; } default: @@ -18546,6 +18505,51 @@ td::string Client::get_chat_member_status(const object_ptr<td_api::ChatMemberSta } } +td::string Client::get_date_time_format(const object_ptr<td_api::DateTimeFormattingType> &formatting_type) { + if (formatting_type == nullptr) { + return td::string(); + } + switch (formatting_type->get_id()) { + case td_api::dateTimeFormattingTypeRelative::ID: + return "r"; + case td_api::dateTimeFormattingTypeAbsolute::ID: { + td::string format; + auto abs = static_cast<const td_api::dateTimeFormattingTypeAbsolute *>(formatting_type.get()); + if (abs->show_day_of_week_) { + format += 'w'; + } + switch (abs->date_precision_->get_id()) { + case td_api::dateTimePartPrecisionNone::ID: + break; + case td_api::dateTimePartPrecisionShort::ID: + format += 'd'; + break; + case td_api::dateTimePartPrecisionLong::ID: + format += 'D'; + break; + default: + UNREACHABLE(); + } + switch (abs->time_precision_->get_id()) { + case td_api::dateTimePartPrecisionNone::ID: + break; + case td_api::dateTimePartPrecisionShort::ID: + format += 't'; + break; + case td_api::dateTimePartPrecisionLong::ID: + format += 'T'; + break; + default: + UNREACHABLE(); + } + return format; + } + default: + UNREACHABLE(); + return {}; + } +} + 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 1921959..23bb9d8 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -1458,6 +1458,8 @@ class Client final : public WebhookActor::Callback { static td::string get_chat_member_status(const object_ptr<td_api::ChatMemberStatus> &status); + static td::string get_date_time_format(const object_ptr<td_api::DateTimeFormattingType> &formatting_type); + static td::string get_passport_element_type(int32 id); static object_ptr<td_api::PassportElementType> get_passport_element_type(td::Slice type); |
