Skip to content

Commit

Permalink
issue #9696: bug 466064 Formatting-options for $datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Mar 10, 2023
1 parent 3d349de commit 6c4c78f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,11 @@ doxygen -w html new_header.html new_footer.html new_stylesheet.css YourConfigFil
<dt><code>$date</code><dd>will be replaced with the current date.
<dt><code>$time</code><dd>will be replaced with the current time.
<dt><code>$year</code><dd>will be replaces with the current year.
<dt><code>$showdate(<format>)</code><dd>will be replaced with the current date
and time according to the format as specified by `<format>`. The
`<format>` follows the rules as specified for the
\ref cmdshowdate "\\showdate" command with the exception that no `)`
is allowed in the `<format>`.
<dt><code>$doxygenversion</code><dd>will be replaced with the version of doxygen
<dt><code>$projectname</code><dd>will be replaced with the name of
the project (see \ref cfg_project_name "PROJECT_NAME")
Expand Down Expand Up @@ -2977,6 +2982,11 @@ doxygen -w latex new_header.tex new_footer.tex new_stylesheet.sty
<dt><code>$date</code><dd>will be replaced with the current date.
<dt><code>$time</code><dd>will be replaced with the current time.
<dt><code>$year</code><dd>will be replaces with the current year.
<dt><code>$showdate(<format>)</code><dd>will be replaced with the current date
and time according to the format as specified by `<format>`. The
`<format>` follows the rules as specified for the
\ref cmdshowdate "\\showdate" command with the exception that no `)`
is allowed in the `<format>`.
<dt><code>$doxygenversion</code><dd>will be replaced with the version of doxygen
<dt><code>$projectname</code><dd>will be replaced with the name of
the project (see \ref cfg_project_name "PROJECT_NAME")
Expand Down
48 changes: 45 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3355,8 +3355,36 @@ QCString substituteKeywords(const QCString &s,const KeywordSubstitutionList &key
size_t keyLen = qstrlen(kw.keyword);
if (qstrncmp(p,kw.keyword,keyLen)==0)
{
substRes+=kw.getValue().str();
p+=keyLen;
const char *startArg = p+keyLen;
bool expectParam = std::holds_alternative<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
//printf("%s: expectParam=%d *startArg=%c\n",kw.keyword,expectParam,*startArg);
if (expectParam && *startArg=='(') // $key(value)
{
size_t j=1;
const char *endArg = 0;
while ((c=*(startArg+j)) && c!=')' && c!='\n' && c!=0) j++;
if (c==')') endArg=startArg+j;
if (endArg)
{
QCString value = QCString(startArg+1).left(endArg-startArg-1);
auto &&getValue = std::get<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
substRes+=getValue(value).str();
p=endArg+1;
//printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue(value)));
}
else
{
//printf("missing argument\n");
p+=keyLen;
}
}
else if (!expectParam) // $key
{
auto &&getValue = std::get<KeywordSubstitution::GetValue>(kw.getValueVariant);
substRes+=getValue().str();
//printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue()));
p+=keyLen;
}
found = true;
break;
}
Expand All @@ -3372,6 +3400,19 @@ QCString substituteKeywords(const QCString &s,const KeywordSubstitutionList &key
return substRes;
}

static QCString showDate(const QCString &fmt)
{
// get the current date and time
std::tm dat{};
int specFormat=0;
QCString specDate = "";
QCString err = dateTimeFromString(specDate,dat,specFormat);

// do the conversion
int usedFormat=0;
return formatDateTime(fmt,dat,usedFormat);
}

QCString substituteKeywords(const QCString &s,const QCString &title,
const QCString &projName,const QCString &projNum,const QCString &projBrief)
{
Expand All @@ -3388,7 +3429,8 @@ QCString substituteKeywords(const QCString &s,const QCString &title,
{ "$projectnumber", [&]() { return projNum; } },
{ "$projectbrief", [&]() { return projBrief; } },
{ "$projectlogo", [&]() { return stripPath(Config_getString(PROJECT_LOGO)); } },
{ "$langISO", [&]() { return theTranslator->trISOLang(); } }
{ "$langISO", [&]() { return theTranslator->trISOLang(); } },
{ "$showdate", [&](const QCString &fmt) { return showDate(fmt); } }
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <algorithm>
#include <functional>
#include <fstream>
#include <variant>

#include <ctype.h>
#include "types.h"
Expand Down Expand Up @@ -198,7 +199,9 @@ bool leftScopeMatch(const QCString &scope, const QCString &name);
struct KeywordSubstitution
{
const char *keyword;
std::function<QCString()> getValue;
using GetValue = std::function<QCString()>;
using GetValueWithParam = std::function<QCString(const QCString &)>;
std::variant<GetValue,GetValueWithParam> getValueVariant;
};

using KeywordSubstitutionList = std::vector<KeywordSubstitution>;
Expand Down

0 comments on commit 6c4c78f

Please sign in to comment.