
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. :-) Thank you! Best Benjamin

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 -----------------------------------------------------------------

Hi Hans, Thanks for sharing this so quickly! I should probably wikify how to get these files compile: I first placed it in "tex/texmf-local" and ran "context --make" and "mtxrun --generate" didn't seem to do the trick for me. I also tried the same after placing the file in "tex/context/modules/mkxl" (where the "crappyspec" module resides), but although I get the "temp-new" module to load, I still get complaints about "missing number, treated as zero". Maybe the primitive is not correctly overloaded? Or (more likely) I'm not doing it right to get the mkxl file being executed. :-) Regarding the formatting, maybe this could be constructed similarly to \date[d=25,m=4,y=2008][weekday,month,day,{,~},year] one could specify similarly to other parsers where "m" is reserved for "month" etc (obviously we could overload as they are associated with \date[] and not with \time[]). H= % hours as decimal number (0–24) I= % hours as decimal number (0–12) [not sure if needed] M= % minute as decimal number (0–59) S= % Seconds as decimal number (0–61) p % (optional) AM/PM indicator in the locale; used in conjunction with I and not with H u % (optional) unit for durations so \time[H=16,M=32][hour,{:},minute] % 16:32 \time[H=16,M=32][hour,{:},minute,{ },indicator] % 4:32 pm and one could "hijack" the command for durations as well (with some overloading similar to "m", "MONTH", "mm", "month" etc.) \time[M=3,S=30,u=minute][MM,{:},SS,{ },unit] % 04:32 min (Unit would take abbreviation from the units module, ideally.) Then \setuplangauge[en][time={HH, :, MM, :, p}] Just a couple of thoughts though. Thank you for all your help! Benjamin
On Jun 10, 2025, at 05:45, Hans Hagen
wrote: 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 -----------------------------------------------------------------

On 6/10/2025 6:54 PM, Benjamin Buchmuller wrote:
Hi Hans,
Thanks for sharing this so quickly!
I should probably wikify how to get these files compile: I first placed it in "tex/texmf-local" and ran "context --make" and "mtxrun --generate" didn't seem to do the trick for me. I also tried the same after placing the file in "tex/context/modules/mkxl" (where the "crappyspec" module resides), but although I get the "temp-new" module to load, I still get complaints about "missing number, treated as zero". Maybe the primitive is not correctly overloaded? Or (more likely) I'm not doing it right to get the mkxl file being executed. :-)
Regarding the formatting, maybe this could be constructed similarly to
\date[d=25,m=4,y=2008][weekday,month,day,{,~},year]
one could specify similarly to other parsers where "m" is reserved for "month" etc (obviously we could overload as they are associated with \date[] and not with \time[]).
But is that really needed used? Maybe overkill.
H= % hours as decimal number (0–24) I= % hours as decimal number (0–12) [not sure if needed] M= % minute as decimal number (0–59) S= % Seconds as decimal number (0–61) p % (optional) AM/PM indicator in the locale; used in conjunction with I and not with H u % (optional) unit for durations
For time there's always the lua one (we could pass that one)
so
\time[H=16,M=32][hour,{:},minute] % 16:32
\time[H=16,M=32][hour,{:},minute,{ },indicator] % 4:32 pm
let's go step by step ...
and one could "hijack" the command for durations as well (with some overloading similar to "m", "MONTH", "mm", "month" etc.)
\time[M=3,S=30,u=minute][MM,{:},SS,{ },unit] % 04:32 min
(Unit would take abbreviation from the units module, ideally.)
Then
\setuplangauge[en][time={HH, :, MM, :, p}]
Just a couple of thoughts though. Thank you for all your help!
That is something to coordinate with Tomas Hala, as he has students from all over the world who provide language specific info. SOmethign we can discuss at the meeting. 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 -----------------------------------------------------------------

Hi Hans, Thanks for the follow-up! I'm not sure about what the easiest approach would be, but one of the strengths of ConTeXt is certainly the ability to "automatically" convert the same input into different representations in the output depending on setups rather than changing the document source. So, ideally "time" would allow this similar to "date" to convert "16:40" into "16:40 Uhr" or "4:40 pm" or similar. (Maybe allowing to adjust durations as well.) The date command is quite sophisticated, I agree. Whether formatting is handled more easily on the lua end or not, I can't really gauge. There is in fact a great number of formatting keys available that might be easy to parse in the context interface. So, maybe all that is needed is an optional secondary argument "format="? I could come up with: \startluacode userdata = userdata or {} function userdata.mytime(str, fmt) local datetable = {} for key, value in str:gmatch("(%w+)%s*=%s*(%d+)") do datetable[key] = tonumber(value) end context.type(os.date("%X", os.time(datetable))) end \stopluacode \def\mytime#1#2{\ctxlua{userdata.mytime([==[#1]==], [==[#2]==])}} \mytime{year=1970, month=1, day=1, hour=0, sec=1}{} However, I don't know how to convert/handle the different escape characters ("%") required for the format string. Just an idea. :-) Thank you — I'll also try the files you shared soon! Ben
On Jun 10, 2025, at 17:27, Hans Hagen
wrote: On 6/10/2025 6:54 PM, Benjamin Buchmuller wrote:
Hi Hans, Thanks for sharing this so quickly! I should probably wikify how to get these files compile: I first placed it in "tex/texmf-local" and ran "context --make" and "mtxrun --generate" didn't seem to do the trick for me. I also tried the same after placing the file in "tex/context/modules/mkxl" (where the "crappyspec" module resides), but although I get the "temp-new" module to load, I still get complaints about "missing number, treated as zero". Maybe the primitive is not correctly overloaded? Or (more likely) I'm not doing it right to get the mkxl file being executed. :-) Regarding the formatting, maybe this could be constructed similarly to \date[d=25,m=4,y=2008][weekday,month,day,{,~},year] one could specify similarly to other parsers where "m" is reserved for "month" etc (obviously we could overload as they are associated with \date[] and not with \time[]).
But is that really needed used? Maybe overkill.
H= % hours as decimal number (0–24) I= % hours as decimal number (0–12) [not sure if needed] M= % minute as decimal number (0–59) S= % Seconds as decimal number (0–61) p % (optional) AM/PM indicator in the locale; used in conjunction with I and not with H u % (optional) unit for durations
For time there's always the lua one (we could pass that one)
so \time[H=16,M=32][hour,{:},minute] % 16:32 \time[H=16,M=32][hour,{:},minute,{ },indicator] % 4:32 pm
let's go step by step ...
and one could "hijack" the command for durations as well (with some overloading similar to "m", "MONTH", "mm", "month" etc.) \time[M=3,S=30,u=minute][MM,{:},SS,{ },unit] % 04:32 min (Unit would take abbreviation from the units module, ideally.) Then \setuplangauge[en][time={HH, :, MM, :, p}] Just a couple of thoughts though. Thank you for all your help!
That is something to coordinate with Tomas Hala, as he has students from all over the world who provide language specific info. SOmethign we can discuss at the meeting.
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 -----------------------------------------------------------------

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. :-)
%D A (simple) time formatter: %D %D \starttyping %D time : \the\time %D time current : \time[method=current] % hh:mm:ss %D time start : \time[method=start] % hh:mm:ss startup time %D time here : \time[method=here] % hh:mm:ss time since startup %D time m : \time[m=100] % hh:mm %D time s : \time[s=3661] % hh:mm:ss %D \stoptyping So a few more times as we had these available anyway. In next upload but then you need to wikify it pending setups, 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 -----------------------------------------------------------------
participants (3)
-
Benjamin Buchmuller
-
Hans Hagen
-
Hans Hagen