10

In the datetime package, we have the command \newdate which allows you to save a date for later use.

In the same line, without thinking much, I tried to use: \newtime{examstart}{09}{00} and was rather surprised to find that this command does not exist.

A search reveals that actually there is nothing similar to \newdate for saving a time for later use.

What do you think will be the best way to save a time for later use?

Definitely, I will want to save the in some structured manner making further processing including formatting possible, just like the \newdate command.

Masroor
  • 17,842

1 Answers1

13

Just mimick what datetime does for \newtime:

\documentclass{article}
\usepackage{datetime}

\makeatletter
\newcommand{\newtime}[3]{%
  \@ifundefined{time@#1@h}
    {\@namedef{time@#1@h}{#2}\@namedef{time@#1@m}{#3}}
    {\PackageError{datetime}{Time `#1' already defined}{}}%
}
\newcommand{\displaytime}[1]{%
  \@ifundefined{time@#1@h}
    {\PackageError{datetime}{Date `#1' not defined}{}}
    {\formattime{\@nameuse{time@#1@h}}{\@nameuse{time@#1@m}}{00}}%
}
\makeatother

\newtime{now}{15}{43}
\newtime{wow}{21}{12}

\begin{document}

\displaytime{now}

\displaytime{wow}

\end{document}
egreg
  • 1,121,712