The gitinfo2
package provides the command \gitAuthorDate
which returns the date of the current commit in ISO format, e.g., 2018-02-22
.
I would like to use this date with a different format within in my document, so I tried to use the datetime2
package to save the output of \gitAuthorDate
and reformat it.
Here is a minimal example (to be used in a git-versioned directory with the appropriate hooks installed as per the documentation of gitinfo2
:
\documentclass{article}
\usepackage[grumpy,mark]{gitinfo2}
\usepackage[calc]{datetime2}
\DTMsavedate{commitdate}{\gitAuthorDate}
\begin{document}
Hello world!
\end{document}
Unfortunately, this gives me
Runaway argument?
\gitInf@authsdate \@dtm@endparsedate \cslet {@dtm@commitdate@year}{\@dtm@year \
ETC.
! Paragraph ended before \@dtm@parsedate was complete.
<to be read again>
\par
l.9
How can I fix this error, or is there another way to reformat the date provided by \gitAuthorDate
?
Edit
As requested by Nicola, here is an excerpt of an interactive session to see how \gitAuthorDate expands
*\show\gitAuthorDate
...
> \gitAuthorDate=\long macro:
->\gitInf@authsdate .
*\makeatletter
*\show\gitInf@authsdate
> \gitInf@authsdate=macro:
->2018-02-22.
\DTMsavedate
performs a one-level expansion on the first token in the second argument, so it would work if, say,\gitAuthorDate
is define as2018-02-22
but not if it's defined in a more complicated manner. For those who don't have git, it would help to know exactly how\gitAuthorDate
expands. Can you add\show\gitAuthorDate
before\DTMsavedate
and add the result.\makeatletter\DTMsavedate{commitdate}{\gitInf@authsdate}\makeatother
, it works as expected. Are there any side-effects or is there a better solution? Otherwise, I am happy to keep this solution.