0

I would like to add time, automatically, so that Latex can build a schedule.

This is known for dates, but would it be possible that a package exists or something similar for time.

\documentclass{article}
\usepackage{datenumber}

\begin{document}

\setdatetoday
\addtocounter{datenumber}{30}%
\setdatebynumber{\thedatenumber}%
In 30 days is \datedate


10:30-\addtime{10:30}{0:45}  - talk 1  \\   %this would add 45min
\addtime{10:30}{0.45}-\addtime{10:30}{1:30}  talk 2   \\ %this would add 1h30min


\end{document}
user98734
  • 173

1 Answers1

3

I don't know a package for this, but a macro can be written:

This has a LaTeX counter overflowdays containing 1, if the time went over midnight (example in code).

enter image description here

\documentclass{article}
\usepackage{datenumber}

\makeatletter
\newcount\@hours
\newcount\@minutes
\newcounter{overflowdays}
\newcommand*{\addtime}[2]{%
    \@add@time#1\@@atendi#2\@@atendii
}
\def\@add@time#1:#2\@@atendi#3:#4\@@atendii{%
    % add hours
    \@hours=#1\advance\@hours#3\relax
    % add minutes
    \@minutes=#2\advance\@minutes#4\relax
    % get full hours from minutes
    \@tempcnta\@minutes\divide\@tempcnta60\relax
    % add them to the hours
    \advance\@hours\@tempcnta
    % full hours from minutes back to minutes
    \multiply\@tempcnta60\relax
    % and subtract from minutes
    \advance\@minutes-\@tempcnta
    % get full days from hours
    \@tempcnta\@hours\divide\@tempcnta24\relax
    % set overflowday
    \setcounter{overflowdays}{\@tempcnta}%
    % full days from hours back to hours
    \multiply\@tempcnta24\relax
    % and subtract from hours
    \advance\@hours-\@tempcnta
    % give out
    \ifnum\@hours<10\relax0\fi% comment out to get rid of leading 0 for hours
    \the\@hours:\ifnum\@minutes<10\relax0\fi\the\@minutes
}
\makeatother

\begin{document}

\setdatetoday
\addtocounter{datenumber}{30}%
\setdatebynumber{\thedatenumber}%
In 30 days is \datedate


10:30-\addtime{10:30}{0:45}  - talk 1  \\   %this would add 45min
\addtime{10:30}{0:45}-\addtime{10:30}{1:30}  talk 2   \\ %this would add 1h30min

Works too (\verb|\addtime{23:30}{2:00}|): \addtime{23:30}{2:00} and we are \theoverflowdays\ day(s) further

There is no input controll (\verb|\addtime{25:90}{30:70}|): \addtime{25:90}{30:70} (days: \theoverflowdays)

\end{document}
Mike
  • 8,664