On 6/10/2025 2:35 AM, Benjamin Buchmuller wrote:
Hi list,

I was wondering if there is a "\time" equivalent similar to "\currentdate" -> 
"\date"?

I know from the wiki (and source) that there is "\currenttime", but "\time[h=8, m=30]" 
will not typeset "8:30", so it doesn't seem to be implemented. I understand that such an 
implementation might become arbitrarily complicated …

In fact, I'm trying to typeset durations like "3:30 min" which is not exactly a 
"time" either, but neither \unit{3:30 minute} nor a math formula achieve the expected 
rendering. Of course, one could just type it plainly, but maybe this little gap is worthwhile 
considering in a future version. :-)

It's no problem to add something and it's kind of trivial to implement anyway. See attached.

You need to keep in mind that \time is also a primitive (do users actually use that one?) so we need to remain compatible with its usage as number, think:

\time1234 % sets the time

\time[]   % typesets the time

\the\time % typesets the number

intercepting h and m also has to involve overflow

how about seconds? and pm/am ?

you can test the attached proof of concept and contemplate the above (and do some research in language dependencies) .. when i got enough input we can (after wolfgangs quality assurance check) add something to the core (in order to keep the format small i can then kick out something unused)

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
\starttext

\unprotect \pushoverloadmode

\setnewconstant \plussixty      60
\setnewconstant \plustwentyfour 24

\permanent\tolerant\protected\def\time[#1]%
  {\ifarguments
     \expandafter\normaltime
   \or
     \begingroup
     \resetdummyparameter h%
     \resetdummyparameter m%
     \ifempty{\dummyparameter h\dummyparameter m}%
       \setdummyparameter h{\normaltime/\plussixty}%
       \setdummyparameter m{\normaltime;\plussixty}%
     \else
       \letdummyparameter h\zerocount
       \letdummyparameter m\zerocount
     \fi
     \setdummyparameter\c!separator{:}%
     \getdummyparameters[#1]%
     \scratchcounterone{\dummyparameter h}%
     \scratchcountertwo{\dummyparameter m}%
     \advanceby\scratchcounterone{\scratchcountertwo/\plussixty}%
     \scratchcountertwo{\scratchcountertwo;\plussixty}%
     \scratchcounterone{\scratchcounterone;\plustwentyfour}%
     \ifnum\scratchcounterone<\plusten0\fi\tointeger\scratchcounterone
     \dummyparameter\c!separator
     \ifnum\scratchcountertwo<\plusten0\fi\tointeger\scratchcountertwo
     \endgroup
   \fi}

\popoverloadmode \protect

todo:

\startitemize
\startitem either of not leading zero \stopitem
\startitem AM/PM but where and is this language dependent \stopitem
\stopitemize

\startlines
primitive: \the\time
test: \time[m=40] \time[m=100] \time[]
\stoplines

\dorecurse{100}{
    \dorecurse{200}{
        \time[h=#1,m=##1]
    }
    \par
}

\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to