Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_time.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
26
27#ifndef __TIME_C_IMPLEMENTATION__
28#define __TIME_C_IMPLEMENTATION__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include "n_common.h"
35
36#include <time.h>
37#include <limits.h>
38#include "nilorea/n_windows.h"
39#ifndef __windows__
40#include <sys/time.h>
41#endif
42
47
49typedef struct N_TIME {
51 time_t delta;
52#ifdef __windows__
54 LARGE_INTEGER freq;
56 LARGE_INTEGER startTime;
58 LARGE_INTEGER currentTime;
59#else
61 struct timeval startTime;
63 struct timeval currentTime;
64#endif
65} N_TIME;
66
68#if defined __windows__
69void u_sleep(__int64 usec);
70#else
71void u_sleep(unsigned int usec);
72#endif
73
75void PAUSE(void);
76
78int start_HiTimer(N_TIME* timer);
79
81time_t get_usec(N_TIME* timer);
82
84time_t get_msec(N_TIME* timer);
85
87time_t get_sec(N_TIME* timer);
88
90#define N_TIME_HTTP_DATE_LEN 30
92#define N_TIME_RFC2822_LEN 32
94#define N_TIME_RFC3339_LEN 26
95
104int n_time_http_date(time_t t, char* out, size_t size);
105
116int n_time_parse_http_date(const char* s, size_t len, time_t* t);
117
127int n_time_rfc2822(time_t t, long offset, char* out, size_t size);
128
138int n_time_rfc3339(time_t t, long offset, char* out, size_t size);
139
148int n_time_parse_rfc3339(const char* s, size_t len, time_t* t);
149
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif /* #ifndef __COMMON_FOR_C_IMPLEMENTATION__ */
struct timeval startTime
start time
Definition n_time.h:61
time_t delta
time since last poll
Definition n_time.h:51
struct timeval currentTime
current time
Definition n_time.h:63
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")
Definition n_time.c:313
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
Definition n_time.c:254
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]"
Definition n_time.c:340
void u_sleep(unsigned int usec)
sleep for the given number of microseconds
Definition n_time.c:55
int start_HiTimer(N_TIME *timer)
Init or restart from zero any N_TIME HiTimer.
Definition n_time.c:86
time_t get_usec(N_TIME *timer)
Poll any N_TIME HiTimer, returning usec.
Definition n_time.c:108
time_t get_msec(N_TIME *timer)
Poll any N_TIME HiTimer, returning msec.
Definition n_time.c:129
time_t get_sec(N_TIME *timer)
Poll any N_TIME HiTimer, returning sec.
Definition n_time.c:150
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)
Definition n_time.c:237
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
Definition n_time.c:272
void PAUSE(void)
for the 'press a key to continue'
Definition n_time.c:63
Timing Structure.
Definition n_time.h:49
Common headers and low-level functions & define.