I would like to display the time of the day like 18h30 or 18h30m with siunitx
. Is there a proper way to display time and time intervals?
I have read some discussions on the Mailing-List, but it seems to be outdated.
My personal solution was defining the following command:
\newcommand{\hms}[3]{
% Stunden nur zeigen, wenn gesetzt
\ifthenelse{\isempty{#1}}
{}
{\SI{#1}{\hour}}
%
% Luecke nur, wenn Stunden und Minuten
\ifthenelse{\isempty{#1} \OR \isempty{#2}}
{}
{\,\,}
%
% Minuten nur zeigen, wenn gesetzt
\ifthenelse{\isempty{#2}}
{}
{\SI{#2}{\minute}}
% %
% Luecke nur, wenn Minuten und Sekunden
\ifthenelse{\isempty{#2} \OR \isempty{#3}}
{}
{\,\,}
%
%Luecke nur, wenn Sekunden und Stunden aber nicht Minuten
\ifthenelse{\isempty{#2} \AND \NOT \isempty{#3} \AND \NOT \isempty{#1}}
{\,\,}
{}
%
% Sekunden nur zeigen, wenn gesetzt
\ifthenelse{\isempty{#3}}
{}
{\SI{#3}{\second}}
}
What is your opinion? How would you typeset times and time periods?
Best Answer
I've been asked about this a few times. It's an awkward one, as the format people want ('18 h 30 min', for example) is really not a single idea for expressing a time in scientific work. You'd normally want to express in one unit, so in either hours or minutes, but not both. That said, it's not too hard to construct a function
\hms
which works in a similar way to\ang
(the multiple-unit argument applies to the later too!). This needs a code test as well as\IfNoValueTF
, which is a little awkward for end users, but something likeshould do what you want. I've included an optional first argument for local set up in the usual
siunitx
way.