Tcl_GetTime(3tcl)
π Tcl_GetTime β get date and time π
okay bestie, so this is a page from the Tcl Library Procedures manual, and it's literally all about grabbing the current date and time, plus the whole β¨virtual timeβ¨ situation. It's Tcl_GetTime(3tcl), she's iconic, let's get into it π«Ά
πΈ NAME πΈ
Tcl_GetTime, Tcl_SetTimeProc, Tcl_QueryTimeProc β get date and time
β¨ SYNOPSIS β¨
#include <tcl.h>
Tcl_GetTime(timePtr)
Tcl_SetTimeProc(getProc, scaleProc, clientData)
Tcl_QueryTimeProc(getProcPtr, scaleProcPtr, clientDataPtr)
π ARGUMENTS π
Tcl_Time *timePtr(out) β points to memory where we're gonna stash the date and time info. you bring the memory, she fills it πTcl_GetTimeProc getProc(in) β pointer to a handler function that replacesTcl_GetTime's access to the OS. yes bestie, you can swap out how time is gotten.Tcl_ScaleTimeProc scaleProc(in) β pointer to a handler function for converting time delays in the virtual domain into real-time.void *clientData(in) β a value that gets passed straight through to the two handler functions. just vibes, carried along.Tcl_GetTimeProc *getProcPtr(out) β pointer to a place where the currently registered get handler function goes.Tcl_ScaleTimeProc *scaleProcPtr(out) β pointer to a place where the currently registered scale handler function goes.void **clientDataPtr(out) β pointer to a place where the currently registered pass-through value goes.
π¦ DESCRIPTION π¦
So Tcl_GetTime retrieves the current time as a Tcl_Time structure, and it puts it in memory that the caller provides. the structure is giving:
typedef struct {
long long sec;
long usec;
} Tcl_Time;
On return, the sec member gets filled in with the number of seconds that have elapsed since the epoch β and the epoch is that point in time of 00:00 UTC, 1 January 1970. periodt. and no, this number does not count leap seconds; an interval of one day advances it by 86400 seconds regardless of whether a leap second has been inserted. the math stays mathing π
The usec member gets filled in with the number of microseconds that have elapsed since the start of the second designated by sec. The Tcl library makes every effort to keep this number as precise as possible, subject to the limitations of the computer system. On multiprocessor variants of Windows, this number may be limited to the 10- or 20-ms granularity of the system clock. (On single-processor Windows systems, the usec field is derived from a performance counter and is highly precise β slay, honestly π
)
π§ VIRTUALIZED TIME π§
The Tcl_SetTimeProc function registers two related handler functions with the core. The first handler function is a replacement for Tcl_GetTime, or rather the OS access made by Tcl_GetTime. The other handler function is used by the Tcl notifier to convert wait/block times from the virtual domain into real time. it's giving time but make it custom β¨
The Tcl_QueryTimeProc function returns the currently registered handler functions. If no external handlers were set then this will return the standard handlers accessing and processing the native time of the OS. The arguments to the function are allowed to be NULL; and any argument which is NULL is ignored and not set. so if you don't care about one of them, just pass NULL and move on bestie π
The signatures of the handler functions are as follows:
typedef void Tcl_GetTimeProc(
Tcl_Time *timebuf,
void *clientData);
typedef void Tcl_ScaleTimeProc(
Tcl_Time *timebuf,
void *clientData);
The timebuf fields contain the time to manipulate, and the clientData fields contain a pointer supplied at the time the handler functions were registered. π
β οΈ okay this part matters: any handler pair specified has to return data which is consistent between them. In other words, setting one handler of the pair to something assuming a 10-times slowdown, and the other handler of the pair to something assuming a two-times slowdown is wrong and not allowed. the two of them have to be on the same page, no mismatched energy fr fr π
The set handler functions are allowed to run the delivered time backwards, however this should be avoided. We have to allow it as the native time can run backwards as the user can fiddle with the system time one way or other. Note that the insertion of the hooks will not change the behavior of the Tcl core with regard to this situation, i.e. the existing behavior is retained. so likeβ¦ it's allowed but don't be weird about it π
π SEE ALSO π
π KEYWORDS π
date, time
and that's the whole page bestie, no notes π This was the Tcl library procedures manual, version 8.4, so thank you for coming to my TED talk, stay precise, stay consistent, and don't run time backwards unless you absolutely have to πβ¨π¦
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms