7

I’m using svn-multi to include the date of the most recent Subversion commit of my documents. However, the string has the format 2013-10-13 11:05:51 +0200 (Sun, 13 Oct 2013). Is it possible to convert this string to the same date format that is used by \today?

Here is a minimal working example (Subversion inserts the date automatically before a commit):

\documentclass{article}

\usepackage{svn-multi}
\svnidlong
{$LastChangedBy: mcb $}
{$LastChangedRevision: 23 $}
{$LastChangedDate: 2013-10-13 11:05:51 +0200 (Sun, 13 Oct 2013) $}
{$HeadURL: http://example.org $}

\title{Sample Document}
\author{Sample}
\date{\svndate}

\begin{document}

\maketitle

\end{document}
Lenar Hoyt
  • 1,629

1 Answers1

12

Here's how to parse the date. The other answer gives links on adjusting the display:

\documentclass{article}

\usepackage{datetime}

\def\parsecommitdate#1-#2-#3 #4:#5:#6 #7\endparse{%
  \date{\formatdate{#3}{#2}{#1}}%
}

\newcommand{\svndate}{2013-10-13 11:05:51 +0200 (Sun, 13 Oct 2013)}

\title{Sample Document}
\author{Sample}

\begin{document}

% Since \svndate is not available in the preamble the date must be set in the document environment.
\expandafter\parsecommitdate\svndate\endparse

\maketitle


\end{document}
Lenar Hoyt
  • 1,629
Nicola Talbot
  • 41,153
  • This works really well, thank you. However, it does not work together with the \svndate (which just prints the date string). The error message is: Paragraph ended before \parsecommitdate was complete. – Lenar Hoyt Oct 13 '13 at 10:37
  • 1
    @mcb You need to expand \svndate before it can be parsed. It \svndate is a one level expansion of the formatted date you can just put \expandafter before \parsecommitdate. – Nicola Talbot Oct 13 '13 at 10:43
  • It doesn’t seem to work with the MWE above. – Lenar Hoyt Oct 13 '13 at 11:13
  • @mcb It compiles fine for me. In what way does it not work for you? (Does it give an error message or produce unexpected output?) – Nicola Talbot Oct 13 '13 at 12:14
  • @NicolaTablot Still the same error: Paragraph ended before \parsecommitdate was complete. (I just copied my MWE from above and added package, definition from your answer and replaced the line with the date.) – Lenar Hoyt Oct 13 '13 at 12:23
  • @mcb Can you edit your post to include a new MWE that shows this? What do you get if you do \show\svndate? If it doesn't show the date in the format you described, then you will get an error. – Nicola Talbot Oct 13 '13 at 13:42
  • @mcb I just did another check. It looks like \svndate doesn't get set until \begin{document}, so make sure your code is in the document environment not in the preamble. – Nicola Talbot Oct 13 '13 at 13:44