fxlibc/include/time.h

72 lines
2.3 KiB
C
Raw Normal View History

2021-06-13 18:26:04 +02:00
#ifndef __TIME_H__
# define __TIME_H__
2021-06-28 15:49:05 +02:00
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
/* Number of ticks per second in a clock_t value. This is not necessarily the
full precision (eg. the RTC has only 128 units per second). */
2021-06-13 18:26:04 +02:00
#define CLOCKS_PER_SEC 1000000
/* Represent process CPU time; unit is CLOCKS_PER_SEC. */
2021-06-13 18:26:04 +02:00
typedef uint64_t clock_t;
/* Represent a number of seconds since 1970-01-01 00:00:00 +0000 (UTC). */
typedef int64_t time_t;
2021-06-13 18:26:04 +02:00
/* Broken-down time. */
struct tm {
int tm_sec; /* Seconds (0..60) */
int tm_min; /* Minutes (0..59) */
int tm_hour; /* Hours (0..23) */
int tm_mday; /* Day of month (1..31) */
int tm_mon; /* Month (0..11) */
int tm_year; /* Years since 1900 */
int tm_wday; /* Day of week, starting Sunday (0..6) */
int tm_yday; /* Day of year (0..365) */
int tm_isdst; /* Daylight Saving Time flag */
2021-06-13 18:26:04 +02:00
};
/* Returns CPU time used by the program (in number of CLOCKS_PER_SEC). */
extern clock_t clock(void);
/* Time elapsed between __start and __end, in seconds. */
double difftime(time_t __end, time_t __start);
/* Normalizes __time and returns associated timestamp.
TODO: Currently ignores the [tm_isdst] field. */
extern time_t mktime(struct tm *__time);
/* Determine current timestamp; also set it in __timeptr if non-NULL. */
extern time_t time(time_t *__timeptr);
/* Text representation, like "Sun Sep 16 01:03:52 1973\n". The returned string
is statically allocated and is overwritten by every call. */
extern char *asctime(const struct tm *__time);
/* Convert calendar time to asctime()'s text representation. */
extern char *ctime(const time_t *__time);
/* Convert calendar time to broken-down time as UTC. */
extern struct tm *gmtime(const time_t *__time);
/* Convert calendar time to broken-down local time.
TODO: We don't have timezones so this always returns UTC. */
extern struct tm *localtime(const time_t *time);
/* Formats __time according to the specified format; similar to snprintf().
TODO: %g, %G, %V (week-based year), and %U, %W (week number) are not
supported and substituted by "??". %z and %Z output nothing. */
size_t strftime(char * restrict __s, size_t __maxsize,
const char * restrict __format, const struct tm * restrict __time);
2021-06-28 15:49:05 +02:00
#ifdef __cplusplus
}
#endif
2021-06-13 18:26:04 +02:00
#endif /*__TIME_H__*/