7 Module N_TIME
gullradriel edited this page 2026-10-29 20:54:40 +01:00

TIMERS: generally used headers, defines, timers, allocators,...

Structures

Name
struct N_TIME
Timing Structure.

Functions

Name
void u_sleep(unsigned int usec)
sleep for the given number of microseconds
int start_HiTimer(N_TIME * timer)
Init or restart from zero any N_TIME HiTimer.
int n_time_rfc3339(time_t t, long offset, char * out, size_t size)
format t as RFC 3339 / ISO 8601 with a numeric offset
int n_time_rfc2822(time_t t, long offset, char * out, size_t size)
format t as an RFC 2822 date with a numeric offset, as RSS wants
int n_time_parse_rfc3339(const char * s, size_t len, time_t * t)
parse "YYYY-MM-DD[T
int n_time_parse_http_date(const char * s, size_t len, time_t * t)
parse an HTTP date in IMF-fixdate form ("Sun, 06 Nov 1994 08:49:37 GMT")
int n_time_http_date(time_t t, char * out, size_t size)
format t as an HTTP date (RFC 9110 IMF-fixdate, always GMT)
time_t get_usec(N_TIME * timer)
Poll any N_TIME HiTimer, returning usec.
time_t get_sec(N_TIME * timer)
Poll any N_TIME HiTimer, returning sec.
time_t get_msec(N_TIME * timer)
Poll any N_TIME HiTimer, returning msec.
void PAUSE(void )
for the 'press a key to continue'

Defines

Name
N_TIME_RFC3339_LEN
buffer size for n_time_rfc3339(): "1970-01-01T00:00:00+00:00" + NUL
N_TIME_RFC2822_LEN
buffer size for n_time_rfc2822(): "Thu, 01 Jan 1970 00:00:00 +0000" + NUL
N_TIME_HTTP_DATE_LEN
buffer size for n_time_http_date(): "Thu, 01 Jan 1970 00:00:00 GMT" + NUL

Functions Documentation

function u_sleep

void u_sleep(
    unsigned int usec
)

sleep for the given number of microseconds

Parameters:

  • usec Number of usec to sleep

wrapper around usleep for API consistency

sleep for the given number of microseconds

function start_HiTimer

int start_HiTimer(
    N_TIME * timer
)

Init or restart from zero any N_TIME HiTimer.

Parameters:

  • timer Any N_TIMER *timer you wanna start or reset

Return: TRUE or FALSE

Initialize or restart from zero any N_TIME HiTimer.

Init or restart from zero any N_TIME HiTimer.

function n_time_rfc3339

int n_time_rfc3339(
    time_t t,
    long offset,
    char * out,
    size_t size
)

format t as RFC 3339 / ISO 8601 with a numeric offset

Parameters:

  • t seconds since the Unix epoch
  • offset offset from UTC in seconds, a multiple of 60, |offset| < 86400
  • out destination, at least N_TIME_RFC3339_LEN bytes
  • size size of out
  • t seconds since the Unix epoch
  • offset offset from UTC in seconds, a multiple of 60, |offset| < 86400
  • out destination, at least N_TIME_RFC3339_LEN bytes
  • size size of out

Return:

  • TRUE, or FALSE on a bad argument
  • TRUE, or FALSE on a bad argument

format t as RFC 3339 at offset seconds east of UTC ("+00:00" for UTC)

"1970-01-01T01:00:00+01:00" (PHP's date('c') for that zone; offset 0 gives "+00:00", not "Z"). format t as RFC 3339 / ISO 8601 with a numeric offset

function n_time_rfc2822

int n_time_rfc2822(
    time_t t,
    long offset,
    char * out,
    size_t size
)

format t as an RFC 2822 date with a numeric offset, as RSS wants

Parameters:

  • t seconds since the Unix epoch
  • offset offset from UTC in seconds, a multiple of 60, |offset| < 86400
  • out destination, at least N_TIME_RFC2822_LEN bytes
  • size size of out
  • t seconds since the Unix epoch
  • offset offset from UTC in seconds, a multiple of 60, |offset| < 86400
  • out destination, at least N_TIME_RFC2822_LEN bytes
  • size size of out

Return:

  • TRUE, or FALSE on a bad argument
  • TRUE, or FALSE on a bad argument

format t as an RFC 2822 date at offset seconds east of UTC

"Thu, 01 Jan 1970 01:00:00 +0100": the local time at offset seconds east of UTC (PHP's date(DATE_RSS) output for that zone). format t as an RFC 2822 date with a numeric offset, as RSS wants

function n_time_parse_rfc3339

int n_time_parse_rfc3339(
    const char * s,
    size_t len,
    time_t * t
)

parse "YYYY-MM-DD[T| ]HH:MM:SS[Z|+hh:mm|-hh:mm]"

Parameters:

  • s the text (may be NULL only when len is 0)
  • len its length
  • t receives seconds since the Unix epoch
  • s the text (may be NULL only when len is 0)
  • len its length
  • t receives seconds since the Unix epoch

Return:

  • TRUE on success, FALSE otherwise
  • TRUE on success, FALSE otherwise

parse "YYYY-MM-DD[T| ]HH:MM:SS[Z|+hh:mm|-hh:mm]" (UTC without a zone)

RFC 3339 timestamps, and the SQL "YYYY-MM-DD HH:MM:SS" form; without a zone the time is UTC. No fractional seconds. Calendar values checked. parse "YYYY-MM-DD[T| ]HH:MM:SS[Z|+hh:mm|-hh:mm]"

function n_time_parse_http_date

int n_time_parse_http_date(
    const char * s,
    size_t len,
    time_t * t
)

parse an HTTP date in IMF-fixdate form ("Sun, 06 Nov 1994 08:49:37 GMT")

Parameters:

  • s the text (may be NULL only when len is 0)
  • len its length
  • t receives seconds since the Unix epoch
  • s the text (may be NULL only when len is 0)
  • len its length
  • t receives seconds since the Unix epoch

Return:

  • TRUE on success, FALSE otherwise
  • TRUE on success, FALSE otherwise

parse an IMF-fixdate HTTP date strictly

Strict: exactly that shape, a weekday that matches the date, real calendar values (no Feb 30, no hour 24, no leap second). The obsolete RFC 850 and asctime forms are refused; a caller handling If-Modified-Since then just ignores the header, which is always safe. parse an HTTP date in IMF-fixdate form ("Sun, 06 Nov 1994 08:49:37 GMT")

function n_time_http_date

int n_time_http_date(
    time_t t,
    char * out,
    size_t size
)

format t as an HTTP date (RFC 9110 IMF-fixdate, always GMT)

Parameters:

  • t seconds since the Unix epoch
  • out destination, at least N_TIME_HTTP_DATE_LEN bytes
  • size size of out
  • t seconds since the Unix epoch
  • out destination, at least N_TIME_HTTP_DATE_LEN bytes
  • size size of out

Return:

  • TRUE, or FALSE when out is NULL / too small or t out of range
  • TRUE, or FALSE when out is NULL / too small or t out of range

For Date, Last-Modified and Expires. Pure calendar arithmetic: no locale, no TZ, no gmtime(), the same result on every platform. Years 1 to 9999.

function get_usec

time_t get_usec(
    N_TIME * timer
)

Poll any N_TIME HiTimer, returning usec.

Parameters:

  • timer Any N_TIMER *timer you wanna poll

Return: The elapsed number of usec for the given N_TIME *timer

Poll any N_TIME HiTimer, returning usec, and moving currentTime to startTime.

Poll any N_TIME HiTimer, returning usec.

function get_sec

time_t get_sec(
    N_TIME * timer
)

Poll any N_TIME HiTimer, returning sec.

Parameters:

  • timer Any N_TIMER *timer you wanna poll

Return: The elapsed number of sec for the given N_TIME *timer

Poll any N_TIME HiTimer, returning sec, and moving currentTime to startTime.

Poll any N_TIME HiTimer, returning sec.

function get_msec

time_t get_msec(
    N_TIME * timer
)

Poll any N_TIME HiTimer, returning msec.

Parameters:

  • timer Any N_TIMER *timer you wanna poll

Return: The elapsed number of msec for the given N_TIME *timer

Poll any N_TIME HiTimer, returning msec, and moving currentTime to startTime.

Poll any N_TIME HiTimer, returning msec.

function PAUSE

void PAUSE(
    void 
)

for the 'press a key to continue'

make a pause in a terminal

for the 'press a key to continue'

Macros Documentation

define N_TIME_RFC3339_LEN

#define N_TIME_RFC3339_LEN 26

buffer size for n_time_rfc3339(): "1970-01-01T00:00:00+00:00" + NUL

define N_TIME_RFC2822_LEN

#define N_TIME_RFC2822_LEN 32

buffer size for n_time_rfc2822(): "Thu, 01 Jan 1970 00:00:00 +0000" + NUL

define N_TIME_HTTP_DATE_LEN

#define N_TIME_HTTP_DATE_LEN 30

buffer size for n_time_http_date(): "Thu, 01 Jan 1970 00:00:00 GMT" + NUL