From 45e17307a1483ca537e25fc27059213085d07119 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 5 Mar 2024 13:34:46 +0000 Subject: [PATCH] Resolve double-indirection CURRENT_DATE in title blocks. If ${COMMENT1} resolves to ${CURRENT_DATE} then we need to resolve again. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17256 (cherry picked from commit da634a618fc8f91ec9e76172c9738986108b7b6b) --- common/title_block.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/common/title_block.cpp b/common/title_block.cpp index def5eecbe2..79cf03c131 100644 --- a/common/title_block.cpp +++ b/common/title_block.cpp @@ -98,6 +98,18 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c bool tokenUpdated = false; wxString originalToken = *aToken; + auto getCurrentDate = + []() -> wxString + { + // We can choose different formats. Should probably be kept in sync with ISSUE_DATE + // formatting in DIALOG_PAGES_SETTINGS. + // + // return wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) ); + // return wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) ); + // return wxDateTime::Now().Format( wxT("%Y-%b-%d") ); + return wxDateTime::Now().FormatISODate(); + }; + if( aToken->IsSameAs( wxT( "ISSUE_DATE" ) ) ) { *aToken = GetDate(); @@ -105,14 +117,7 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c } else if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) ) { - // We can choose different formats. Should probably be kept in sync with ISSUE_DATE - // formatting in DIALOG_PAGES_SETTINGS. - // - // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_SHORT_DATE_FMT ) ); - // *aToken = wxDateTime::Now().Format( wxLocale::GetInfo( wxLOCALE_LONG_DATE_FMT ) ); - // *aToken = wxDateTime::Now().Format( wxT("%Y-%b-%d") ); - *aToken = wxDateTime::Now().FormatISODate(); - + *aToken = getCurrentDate(); tokenUpdated = true; } else if( aToken->IsSameAs( wxT( "REVISION" ) ) ) @@ -152,7 +157,9 @@ bool TITLE_BLOCK::TextVarResolver( wxString* aToken, const PROJECT* aProject ) c if( tokenUpdated ) { - if( aProject ) + if( aToken->IsSameAs( wxT( "CURRENT_DATE" ) ) ) + *aToken = getCurrentDate(); + else if( aProject ) *aToken = ExpandTextVars( *aToken, aProject ); // This is the default fallback, so don't claim we resolved it