%%
%% Mark each page with "DRAFT" and the date and time on the left margin
%% William B. Thompson <thompson@cs.utah.edu>
%%
%% Based on a modified version of the draftwatermark package, written by
%% Sergio Callegari <sergio.callegari@gmail.com> (copyright 2006).
%%
%% Compatible with pdflatex.
%%
%% The font used is the document font, which may or may not be what is
%% desired.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draftdatetime}[2009/12/11 1.2]
\RequirePackage{everypage}
\RequirePackage{graphicx}
\RequirePackage{color}
\newif\if@wbt@ddt@first
\@wbt@ddt@firstfalse
\DeclareOption{firstpage}{%
  \@wbt@ddt@firsttrue}
\ProcessOptions
%
\newcount\wbt@ddt@hours
\newcount\wbt@ddt@minutes
\newcount\wbt@ddt@minutesofhours
\wbt@ddt@hours = \time
\divide\wbt@ddt@hours by 60
\wbt@ddt@minutesofhours = \wbt@ddt@hours
\multiply\wbt@ddt@minutesofhours by 60
\wbt@ddt@minutes = \time
\advance\wbt@ddt@minutes by -\wbt@ddt@minutesofhours
\ifnum\wbt@ddt@hours<10
        \newcommand{\wbt@ddt@printhours}{0\number\wbt@ddt@hours}
    \else
        \newcommand{\wbt@ddt@printhours}{\number\wbt@ddt@hours}
\fi
\ifnum\wbt@ddt@minutes<10
        \newcommand{\wbt@ddt@printminutes}{0\number\wbt@ddt@minutes}
    \else
        \newcommand{\wbt@ddt@printminutes}{\number\wbt@ddt@minutes}
\fi
\newcommand{\wbt@ddt@timeofday}{\wbt@ddt@printhours:\wbt@ddt@printminutes}
%
\newlength\wbt@ddt@fontsize
\newlength\wbt@ddt@width
\newlength\wbt@ddt@height
\newlength\wbt@ddt@hoffset
\newlength\wbt@ddt@voffset
%% defaults
\def\wbt@ddt@angle{90}
\def\wbt@ddt@lightness{0.65}
\def\wbt@ddt@scale{1}
\setlength\wbt@ddt@fontsize{24pt}
\def\wbt@ddt@text%
    {DRAFT \ DRAFT -- \today\ -- \wbt@ddt@timeofday\ -- DRAFT \ DRAFT}
\setlength\wbt@ddt@width{44pt}
\setlength\wbt@ddt@height{-.5\paperheight}
\newcommand\wbt@draft{%
  \setlength{\@tempdimb}{\wbt@ddt@width}%
  \setlength{\@tempdimc}{\wbt@ddt@height}%
  \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
    \makebox(0,0){\rotatebox{\wbt@ddt@angle}{%
        \scalebox{\wbt@ddt@scale}{%
        \textcolor[gray]{\wbt@ddt@lightness}{
          \fontsize{\wbt@ddt@fontsize}{1.2\wbt@ddt@fontsize}
          \selectfont
          \wbt@ddt@text}}}}}}
\newcommand\wbt@ddt@print[1]{%
  % Need to compensate for effects of \vmargin package
  \setlength{\wbt@ddt@hoffset}{1in}\addtolength{\wbt@ddt@hoffset}{\hoffset}
  \setlength{\wbt@ddt@voffset}{-1in}\addtolength{\wbt@ddt@voffset}{-\voffset}
  \setbox\@tempboxa\vbox to \z@{%
    \vskip \wbt@ddt@voffset \moveleft \wbt@ddt@hoffset \vbox{%
      \hbox to \z@{%
        #1\hss}}\vss}
  \dp\@tempboxa\z@
  \box\@tempboxa}
\if@wbt@ddt@first
\AddThispageHook{\wbt@ddt@print{\wbt@draft}}
\else
\AddEverypageHook{\wbt@ddt@print{\wbt@draft}}
\fi
\endinput
%%
%% End of file `draftwatermark.sty'.
