I'm trying to write a macros for converting day time to a format, which the pgfgrantt package can understand. Here it is:
\newcommand{\htime}[2][0]{
\StrBefore{#2}{:}[\hours]
\StrBehind{#2}{:}[\minutes]
\pgfmathparse{\hours+\minutes/60+#1}
\pgfmathresult
}
\newcommand{\gantthbar}[3]{
\def\from{\htime[1]{#2}}
\def\to{\htime{#3}}
\ganttbar{#1}{\from}{\to}
}
% \gantthbar{test}{11:15}{12:00} -> \ganttbar{test}{12.25}{12.0}
Compilation failed with an error, I can't resolve:
! Use of \\ganttbar doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
l.37 \gantthbar{test}{11:15}{12:00}
?
This one compiles without errors:
\newcommand{\gantthbar}[3]{
\def\from{\htime[1]{#2}}
\def\to{\htime{#3}}
\ganttbar{#1 \from \to}{12.25}{12.0}
}
Thanks for your help.
Very minimal working example I wrote after reading comments:
\documentclass[a4paper, 12pt]{report}
\usepackage{xstring}
\usepackage{pgfgantt}
\newcommand{\gantthbar}[3]{
\StrBefore{#2}{:}[\hoursfrom]
\StrBehind{#2}{:}[\minutesfrom]
\StrBefore{#3}{:}[\hoursto]
\StrBehind{#3}{:}[\minutesto]
\pgfmathsetmacro\from{\hoursfrom + \minutesfrom / 60 + 1}
\pgfmathsetmacro\to{\hoursto + \minutesto / 60}
\ganttbar{#1}{\from}{\to}
}
\begin{document}
\begin{ganttchart}[vgrid]{24}
\gantthbar{test}{11:15}{12:00}
\end{ganttchart}
\end{document}
\fromnor\toare fully expandable (they containxstringmacros and\pgfmathparse). Another approach is needed, e.g. let\htimeassign a variable like\pgfmathsetmacro\myFrom{…}or use\pgfmathresultdirectly in the parameters to\ganttbar. – Qrrbrbirlbel Jul 29 '13 at 15:04pgfganttonly understands integer values for the time slots (slots being the important word here). You might be interested in my answer to Gantt chart with title list in minutes and hours which could be customized in the same way so that you can use theh:mmformat for the input, too. – Qrrbrbirlbel Jul 29 '13 at 15:24