]> pd.if.org Git - pdclib/blob - includes/time.h
Started implementation of <time.h>
[pdclib] / includes / time.h
1 /* Date and time <time.h>
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #ifndef _PDCLIB_TIME_H
8 #define _PDCLIB_TIME_H _PDCLIB_TIMEH
9
10 #include "_PDCLIB_int.h"
11
12 #ifndef _PDCLIB_SIZE_T_DEFINED
13 #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED
14 typedef _PDCLIB_size_t size_t;
15 #endif
16
17 #ifndef _PDCLIB_NULL_DEFINED
18 #define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED
19 #define NULL _PDCLIB_NULL
20 #endif
21
22 typedef _PDCLIB_time_t time_t;
23 typedef _PDCLIB_clock_t clock_t;
24
25 #define CLOCKS_PER_SEC _PDCLIB_CLOCKS_PER_SEC
26 #define TIME_UTC _PDCLIB_TIME_UTC
27
28 struct timespec
29 {
30     time_t tv_sec;
31     long tv_nsec;
32 };
33
34 struct tm
35 {
36     int tm_sec;   /* 0-60 */
37     int tm_min;   /* 0-59 */
38     int tm_hour;  /* 0-23 */
39     int tm_mday;  /* 1-31 */
40     int tm_mon;   /* 0-11 */
41     int tm_year;  /* years since 1900 */
42     int tm_wday;  /* 0-6 */
43     int tm_yday;  /* 0-365 */
44     int tm_isdst; /* >0 DST, 0 no DST, <0 information unavailable */
45 };
46
47 /* Returns the number of "clocks" in processor time since the invocation
48    of the program. Divide by CLOCKS_PER_SEC to get the value in seconds.
49    Returns -1 if the value cannot be represented in the return type or is
50    not available.
51 */
52 clock_t clock( void );
53
54 /* Returns the difference between two calendar times in seconds. */
55 double difftime( time_t time1, time_t time0 );
56
57 /* Normalizes the values in the broken-down time pointed to by timeptr.
58    Returns the calender time specified by the broken-down time.
59 */
60 time_t mktime( struct tm * timeptr );
61
62 /* Returns the current calender time. If timer is not a NULL pointer, stores
63    the current calender time at that address as well.
64 */
65 time_t time( time_t * timer );
66
67 /* Sets the interval pointed to by ts to the current calender time, based
68    on the specified base.
69    Returns base, if successful, otherwise zero.
70 */
71 int timespec_get( struct timespec * ts, int base );
72
73 /* Converts the broken-down time pointed to by timeptr into a string in the
74    form "Sun Sep 16 01:03:52 1973\n\0".
75 */
76 char * asctime( const struct tm * timeptr );
77
78 /* Equivalent to asctime( localtime( timer ) ). */
79 char * ctime( const time_t * timer );
80
81 /* Converts the calender time pointed to by timer into a broken-down time
82    expressed as UTC.
83    Returns a pointer to the broken-down time, or a NULL pointer if it
84    cannot be represented.
85 */
86 struct tm * gmtime( const time_t * timer );
87
88 /* Converts the calender time pointed to by timer into a broken-down time
89    expressed as local time.
90    Returns a pointer to the broken-down time, or a NULL pointer if if
91    cannot be represented.
92 */
93 struct tm * localtime( const time_t * timer );
94
95 /* Writes the broken-down time pointed to by timeptr into the character
96    array pointed to by s. The string pointed to by format controls the
97    exact output. No more than maxsize charactrs will be written.
98    Returns the number of characters written (excluding the terminating
99    null character), or zero on failure.
100 */
101 size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr );
102
103 #endif