%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
% This package fetches and formats the date of last modification of any    %
% existing file. It is based on an idea by Heiko Oberdiek (2009).          %
%                                                                          %
% This work may be distributed and/or modified under the conditions        %
% of the LaTeX Project Public License, either version 1.3 of this          %
% license or any later version. The latest version of this license         %
% is in http://www.latex-project.org/lppl.txt and version 1.3 or later     %
% is part of all distributions of LaTeX version 2005/12/01 or later.       %
%                                                                          %
% (c) Ahmed Musa 2009                                                      %
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
\ProvidesPackage{getfiledate}
  [2009/03/05 v1.0 Get date of last modification of existing file]
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{etoolbox}
\RequirePackage{xkeyval}
\RequirePackage[table]{xcolor}
\RequirePackage{amssymb}
\RequirePackage{boxedminipage}
\def\gfd@err#1#2{\PackageError{getfiledate}{#1}{#2}}
\def\gfd@warn#1{\PackageWarningNoLine{getfiledate}{#1}}
\def\gfd@head{0ex}
\def\gfd@foot{0ex}
\def\gfd@prefix{The date of last modification of file}
\def\gfd@marker{$\blacktriangleright$}
\def\gfd@markercolor{blue}
\def\gfd@filenamecolor{blue}
\def\gfd@datecolor{blue}
\def\gfd@inlinespace{1em}
\def\gfd@file{getfiledate.sty}
\let\gfd@align@right\relax
\let\gfd@align@left\relax
\newdimen\gfd@width\gfd@width=\hsize
\newdimen\gfd@width@tmp\gfd@width@tmp=\z@
\def\gfd@framesep{3pt}
\def\gfd@framerule{0.4pt}
\def\gfd@framecolor{black}
\def\gfd@separatorcolor{black}
\let\gfd@separator\textbullet
\let\T@C\textcolor
\define@boolkey[gfd]{getfiledate}[gfd@]{boxed}[true]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{prefix}[%
  The date of last modification of file]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{file}{}
\define@key[gfd]{getfiledate}{width}[\hsize]{\gfd@width=#1}
\define@cmdkey[gfd]{getfiledate}[gfd@]{marker}[$\blacktriangleright$]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{markercolor}[blue]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{filenamecolor}[blue]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{datecolor}[blue]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{inlinespace}[1em]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{head}[\baselineskip]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{foot}[\baselineskip]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{framesep}[3pt]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{framerule}[0.4pt]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{separator}[\textbullet]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{framecolor}[black]{}
\define@cmdkey[gfd]{getfiledate}[gfd@]{separatorcolor}[black]{}
\define@choicekey*+[gfd]{getfiledate}{align}[\gfd@val\gfd@nr]%
{center,right,left,justified}[justified]{%
  \ifcase\gfd@nr\relax
    \def\gfd@align@right{\hfil}
    \def\gfd@align@left{\hfil}
  \or
    \def\gfd@align@right{\hfill}
    \let\gfd@align@left\relax
  \or
    \let\gfd@align@right\relax
    \def\gfd@align@left{\hfill}
  \or
    \let\gfd@align@right\relax
    \let\gfd@align@left\relax
  \fi
}{%
  \gfd@err{Inadmissible value '#1' for align}
}
\DeclareOptionX*{\gfd@warn{Unknown option '\CurrentOption' ignored}}
\ExecuteOptionsX[gfd]<getfiledate>{}
\ProcessOptionsX*[gfd]<getfiledate>\relax
\ifcsdef{pdffilemoddate}{}{%
  \gfd@err{Missing command \string\pdffilemoddate}{%
    Use pdfTeX 1.30.0 or later version}
  \expandafter\endinput
}
\long\def\getfiledate#1{%
  \setkeys[gfd]{getfiledate}{#1}
  \par\vspace{\gfd@head}%
  \begingroup
  \gfd@align@right
  \ifgfd@boxed
    \let\gfd@marker\@empty
    \def\gfd@inlinespace{\z@}
    \fboxsep=\gfd@framesep
    \fboxrule=\gfd@framerule
    \gfd@width@tmp=\gfd@width
    \advance\gfd@width@tmp by 2\fboxsep
    \advance\gfd@width@tmp by 2\fboxrule
    \color{\gfd@framecolor}
    \begin{boxedminipage}{\gfd@width@tmp}%
      \normalcolor\gfd@tempa{\gfd@file}\relax
    \end{boxedminipage}%
  \else
    \noindent\gfd@tempa{\gfd@file}%
  \fi
  \gfd@align@left
  \endgroup
  \par\vspace{\gfd@foot}%
}
\def\gfd@tempa#1{%
  \IfFileExists{#1}{%
    \expandafter\expandafter\expandafter
    \gfd@tempb\expandafter\@gobbletwo\pdffilemoddate{#1}
    D:00000000000000\@nil{#1}%
  }{\gfd@err{File '#1' does not exist or wrong path}{%
    Please enter correct filename or path}}
}
\newcommand\gfd@tempb[8]{\gfd@tempc{#1#2#3#4}{#5#6}{#7#8}}
\newcommand\gfd@tempc[9]{\gfd@tempd{#1}{#2}{#3}{#4#5}{#6#7}{#8#9}}
\def\gfd@tempd#1#2#3#4#5#6#7\@nil#8{%
  \parbox{\gfd@width}{%
    \@killglue\noindent%
    \ifcsempty{gfd@marker}{}{\gfd@marker@a}\relax
    \gfd@prefix\space\T@C{\gfd@filenamecolor}{#8}\space
    was\space\T@C{\gfd@datecolor}{#1-#2-#3}\space\T@C{\gfd@separatorcolor}{%
    \gfd@separator}\space\T@C{\gfd@datecolor}{#4:#5:#6}.%
  }
  \@killglue
}
\def\gfd@marker@a{%
  \T@C{\gfd@markercolor}{\gfd@marker}%
  \hskip\gfd@inlinespace plus\z@ minus\z@\relax
}

\endinput
