# Time calculations

Based on a given starting time, I'd like to automatically calculate a time table. Based on https://groups.google.com/forum/#!topic/de.comp.text.tex/BQrRUYmDrHw I put the following MWE together:

\documentclass{beamer}

\newcount\hours
\newcount\minutes

\def\gettime#1:#2\relax#3#4{\def#3{#1}\def#4{#2}}

\newcommand{\add}{%
\expandafter\gettime#1\relax{\hrs}{\mins}%
\expandafter\gettime#2\relax{\addhrs}{\addmins}%
\hours=\hrs\relax%
\advance\hours by \addhrs\relax%
\minutes=\mins\relax%
\advance\minutes by \addmins\relax%
\ifnum\minutes>59\relax%
\advance\minutes by -60\relax%
\advance\hours by 1\relax%
\else%
\ifnum\minutes<0\relax%
\advance\minutes by 60\relax%
\advance\hours by -1\relax%
\fi%
\fi%
\ifnum\hours>23\relax%
\advance\hours by -24\relax%
\else%
\ifnum\hours<0\relax%
\advance\hours by 24\relax%
\fi%
\fi%
\ifnum\minutes<10\relax%
\xdef#1{\number\hours:0\number\minutes}%
\else%
\xdef#1{\number\hours:\number\minutes}%
\fi%
}

\begin{document}
\begin{frame}
\xdef\startTime{09:30}
\begin{tabular}{l l l}
top1 & \startTime{} -- \add\startTime{01:00}\startTime & \textcolor{red}{01:00}\\
top2 & \startTime{} -- \add\startTime{00:45}\startTime & \textcolor{red}{00:45}\\
top3 & \startTime{} -- \add\startTime{00:15}\startTime & \textcolor{red}{00:15}\\
\hline
Sum & \textcolor{red}{09:30} -- \startTime
\end{tabular}
\end{frame}
\end{document}


Now the question:

How can I insert the red denoted times automatically as well? [In values in the third column are the durations] ## 1 Answer

I'm confused as it seems that the red times at the end of the rows are just the durations that are added to \startTime and that the red entry at the bottom of the second column is just the initial start time...so all you need to do is remember these values.

Assuming this is the case if you add these definitions to your preamble:

\newcounter{top}
\newcommand\newStartTime{\refstepcounter{top}%
Top\arabic{top}&\startTime{}--\add\startTime{#1}\startTime& #1\\}
\newenvironment{StartTimes}{%
\def\InitialStartTime{#1}\xdef\startTime{09:30}%
\tabular{lll}Heat & Time & Duration\\\hline}%
{\hline Sum& \InitialStartTime--\startTime\endtabular}


then you can generate your table with:

\begin{StartTimes}{09:30}
\newStartTime{01:00}
\newStartTime{00:45}
\newStartTime{00:15}
\end{StartTimes}


This produces: 