Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_time.c File Reference

Common time functions. More...

#include "nilorea/n_time.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for n_time.c:

Go to the source code of this file.

Data Structures

struct  _n_civil

Functions

static void _civil_from_days (long long z, long long *y, unsigned *m, unsigned *d)
static int _civil_of (time_t t, long offset, _n_civil *c)
static int _civil_to_time (long long y, unsigned mo, unsigned d, unsigned h, unsigned mi, unsigned se, time_t *t)
static long long _days_from_civil (long long y, unsigned m, unsigned d)
static int _digits (const char *s, size_t n, unsigned *v)
static int _leap (long long y)
static unsigned _month_days (long long y, unsigned m)
static int _offset_ok (long offset)
time_t get_msec (N_TIME *timer)
 Poll any N_TIME HiTimer, returning msec, and moving currentTime to startTime.
time_t get_sec (N_TIME *timer)
 Poll any N_TIME HiTimer, returning sec, and moving currentTime to startTime.
time_t get_usec (N_TIME *timer)
 Poll any N_TIME HiTimer, returning usec, and moving currentTime to startTime.
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)
int n_time_parse_http_date (const char *s, size_t len, time_t *t)
 parse an IMF-fixdate HTTP date strictly
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]" (UTC without a zone)
int n_time_rfc2822 (time_t t, long offset, char *out, size_t size)
 format t as an RFC 2822 date at offset seconds east of UTC
int n_time_rfc3339 (time_t t, long offset, char *out, size_t size)
 format t as RFC 3339 at offset seconds east of UTC ("+00:00" for UTC)
void PAUSE (void)
 make a pause in a terminal
int start_HiTimer (N_TIME *timer)
 Initialize or restart from zero any N_TIME HiTimer.
void u_sleep (unsigned int usec)
 wrapper around usleep for API consistency

Variables

static const char *const _month_names [12]
static const char *const _wday_names [7] = {"Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"}

Detailed Description

Common time functions.

Author
Castagnier Mickael
Version
1.0
Date
24/03/05

Definition in file n_time.c.


Data Structure Documentation

◆ _n_civil

struct _n_civil

Definition at line 207 of file n_time.c.

Collaboration diagram for _n_civil:
Data Fields
unsigned hour
unsigned mday
unsigned min
unsigned mon
unsigned sec
unsigned wday_idx
long long year

Function Documentation

◆ _civil_from_days()

void _civil_from_days ( long long z,
long long * y,
unsigned * m,
unsigned * d )
static

Definition at line 179 of file n_time.c.

Referenced by _civil_of().

Here is the caller graph for this function:

◆ _civil_of()

int _civil_of ( time_t t,
long offset,
_n_civil * c )
static

Definition at line 212 of file n_time.c.

References _civil_from_days(), _n_civil::hour, _n_civil::mday, _n_civil::min, _n_civil::mon, _n_civil::sec, _n_civil::wday_idx, and _n_civil::year.

Referenced by n_time_http_date(), n_time_parse_http_date(), n_time_rfc2822(), and n_time_rfc3339().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _civil_to_time()

int _civil_to_time ( long long y,
unsigned mo,
unsigned d,
unsigned h,
unsigned mi,
unsigned se,
time_t * t )
static

Definition at line 295 of file n_time.c.

References _days_from_civil(), _month_days(), and h().

Referenced by n_time_parse_http_date(), and n_time_parse_rfc3339().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _days_from_civil()

long long _days_from_civil ( long long y,
unsigned m,
unsigned d )
static

Definition at line 168 of file n_time.c.

Referenced by _civil_to_time().

Here is the caller graph for this function:

◆ _digits()

int _digits ( const char * s,
size_t n,
unsigned * v )
static

Definition at line 283 of file n_time.c.

Referenced by n_time_parse_http_date(), and n_time_parse_rfc3339().

Here is the caller graph for this function:

◆ _leap()

int _leap ( long long y)
static

Definition at line 197 of file n_time.c.

Referenced by _month_days().

Here is the caller graph for this function:

◆ _month_days()

unsigned _month_days ( long long y,
unsigned m )
static

Definition at line 201 of file n_time.c.

References _leap().

Referenced by _civil_to_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _offset_ok()

int _offset_ok ( long offset)
static

Definition at line 226 of file n_time.c.

Referenced by n_time_rfc2822(), and n_time_rfc3339().

Here is the caller graph for this function:

Variable Documentation

◆ _month_names

const char* const _month_names[12]
static
Initial value:
= {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}

Definition at line 194 of file n_time.c.

Referenced by n_time_http_date(), n_time_parse_http_date(), and n_time_rfc2822().

◆ _wday_names

const char* const _wday_names[7] = {"Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"}
static

Definition at line 193 of file n_time.c.

Referenced by n_time_http_date(), n_time_parse_http_date(), and n_time_rfc2822().