a C standard library for fx Casio calculators
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

#ifndef __TIME_H__
# define __TIME_H__
#ifdef __cplusplus
extern "C" {
#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). */
#define CLOCKS_PER_SEC 1000000
/* Represent process CPU time; unit is CLOCKS_PER_SEC. */
typedef uint64_t clock_t;
/* Represent a number of seconds since 1970-01-01 00:00:00 +0000 (UTC). */
typedef int64_t time_t;
/* 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 */
/* Full time specification with second/nanosecond precision. */
struct timespec {
time_t tv_sec;
long tv_nsec;
/* 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);
#ifdef __cplusplus
#endif /*__TIME_H__*/