[texhax] Time calculations within LaTeX?

E. Krishnan ekmath at asianetindia.com
Sat Feb 9 15:41:44 CET 2008


> Oops! Sort of overlooked that case. Here's the modification to take care of 
> this:

Second oops! (seems to be a day of botch-ups). You want the time to be 
expressed as a decimal and I thought multiplying by the minutes 5/3 would 
do the trick; but that does works only for minutes difference greater than 
5. So here's another modification:

\def\timediff#1:#2-#3:#4 {%
   \setcounter{bh}{#1}
   \setcounter{bm}{#2}
   \setcounter{eh}{#3}
   \setcounter{em}{#4}
   \ifthenelse{\(\value{eh}>\value{bh}\or\value{eh}=\value{bh}\)
               \and\(\value{em}>\value{bm}\or\value{em}=\value{bm}\)}
     {\setcounter{dh}{\value{eh}-\value{bh}}
      \setcounter{dm}{\value{em}-\value{bm}}}
     {\ifthenelse{\(\value{eh}>\value{bh}\or\value{eh}=\value{bh}\)
                  \and\value{em}<\value{bm}}
       {\setcounter{dh}{\value{eh}-\value{bh}-1}
        \setcounter{dm}{60+\value{em}-\value{bm}}}
       {\ifthenelse{\value{eh}<\value{bh}
         \and\(\value{em}>\value{bm}\or\value{em}=\value{bm}\)}
        {\setcounter{dh}{24+\value{eh}-\value{bh}}
         \setcounter{dm}{\value{em}-\value{bm}}}
        {\ifthenelse{\value{eh}<\value{bh}\and\value{em}<\value{bm}}
        {\setcounter{dh}{23+\value{eh}-\value{bh}}
         \setcounter{dm}{60+\value{em}-\value{bm}}}}}{}}
     \setcounter{hrdec}{\value{dm}*5/3}
     \ifthenelse{\value{dm}>5}{\thedh.\thehrdec}{\thedh.0\thehrdec}}


-- 
Krishnan


More information about the texhax mailing list