From 54e26968307b486e1415d37895650ebfef3310a0 Mon Sep 17 00:00:00 2001 From: matheusgomesms Date: Fri, 9 Jan 2026 08:03:42 -0300 Subject: [PATCH] [editor] Automatically create/update check_date Signed-off-by: matheusgomesms --- libs/indexer/editable_map_object.cpp | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/indexer/editable_map_object.cpp b/libs/indexer/editable_map_object.cpp index 7bec87943..d8efaddbc 100644 --- a/libs/indexer/editable_map_object.cpp +++ b/libs/indexer/editable_map_object.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include namespace osm { @@ -42,6 +44,14 @@ bool ExtractName(StringUtf8Multilang const & names, int8_t const langCode, vecto return true; } +std::string GetCurrentDate() +{ + auto const t = std::time(nullptr); + auto const tm = *std::localtime(&t); + std::ostringstream oss; + oss << std::put_time(&tm, "%Y-%m-%d"); + return oss.str(); +} } // namespace // LocalizedName ----------------------------------------------------------------------------------- @@ -851,6 +861,25 @@ void EditableMapObject::ApplyJournalEntry(JournalEntry const & entry) void EditableMapObject::LogDiffInJournal(EditableMapObject const & unedited_emo) { LOG(LDEBUG, ("Executing LogDiffInJournal")); + + // Auto-fill check_date + if (ftypes::IsCheckDateChecker::Instance()(GetTypes())) + { + std::string const currentDate = GetCurrentDate(); + + // Always update check_date + SetMetadata(feature::Metadata::FMD_CHECK_DATE, currentDate); + + // Update check_date:opening_hours if Opening Hours changed + std::string_view const newOH = GetMetadata(feature::Metadata::FMD_OPEN_HOURS); + std::string_view const oldOH = unedited_emo.GetMetadata(feature::Metadata::FMD_OPEN_HOURS); + + // If new OH exists and is different from old (or old was empty), update the date. + if (!newOH.empty() && newOH != oldOH) + { + SetMetadata(feature::Metadata::FMD_CHECK_DATE_OPEN_HOURS, currentDate); + } + } // Name for (StringUtf8Multilang::Lang language : StringUtf8Multilang::GetSupportedLanguages())