[editor] Automatically create/update check_date

Signed-off-by: matheusgomesms <matheusgomesms@noreply.codeberg.org>
This commit is contained in:
matheusgomesms
2026-01-09 08:03:42 -03:00
parent 5e8d2e1a59
commit 54e2696830

View File

@@ -17,6 +17,8 @@
#include <cmath>
#include <regex>
#include <sstream>
#include <ctime>
#include <iomanip>
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())