Loading [MathJax]/jax/output/HTML-CSS/config.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
time.h File Reference
#include <sys/timespec.h>
Include dependency graph for time.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tm
 

Functions

time_t time (time_t *t)
 
char * asctime_r (const struct tm *tm, char *buf)
 
char * asctime (const struct tm *tm)
 
char * ctime_r (const time_t *timep, char *buf)
 
char * ctime (const time_t *timep)
 
struct tmgmtime (const time_t *timep)
 
struct tmgmtime_r (const time_t *timep, struct tm *result)
 
struct tmlocaltime (const time_t *timep)
 
struct tmlocaltime_r (const time_t *timep, struct tm *result)
 
time_t mktime (struct tm *tm)
 

Data Structure Documentation

◆ tm

struct tm

Definition at line 7 of file time.h.

Collaboration diagram for tm:
[legend]
Data Fields
int tm_hour
int tm_isdst
int tm_mday
int tm_min
int tm_mon
int tm_sec
int tm_wday
int tm_yday
int tm_year

Function Documentation

◆ asctime()

char * asctime ( const struct tm tm)

Definition at line 64 of file time.c.

65{
66 static char buf[26];
67 return asctime_r(tm, buf);
68}
static char buf[4096]
Definition: ethdump.c:10
Definition: time.h:7
char * asctime_r(const struct tm *tm, char *buf)
Definition: time.c:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ asctime_r()

char * asctime_r ( const struct tm tm,
char *  buf 
)

Definition at line 50 of file time.c.

51{
52 // assert(tm->tm_wday < 7);
53 // assert(tm->tm_mon < 12);
54
55 snprintf(buf, 26, "%s %s %2d %2d:%02d:%02d %4d\n",
58 tm->tm_sec, tm->tm_year + 1900);
59
60 return buf;
61}
int tm_mon
Definition: time.h:12
int tm_year
Definition: time.h:13
int tm_hour
Definition: time.h:10
int tm_sec
Definition: time.h:8
int tm_mday
Definition: time.h:11
int tm_min
Definition: time.h:9
int tm_wday
Definition: time.h:14
static const char * months[12]
Definition: time.c:14
static const char * dayOfWeek[7]
Definition: time.c:13
int snprintf(char *str, size_t size, const char *fmt,...) __printflike(3
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctime()

char * ctime ( const time_t timep)

Definition at line 78 of file time.c.

79{
80 return asctime(localtime(timep));
81}
struct tm * localtime(const time_t *timep)
Definition: time.c:178
char * asctime(const struct tm *tm)
Definition: time.c:64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctime_r()

char * ctime_r ( const time_t timep,
char *  buf 
)

Definition at line 71 of file time.c.

72{
73 struct tm tm;
74 return asctime_r(localtime_r(timep, &tm), buf);
75}
struct tm * localtime_r(const time_t *timep, struct tm *result)
Definition: time.c:171
Here is the call graph for this function:

◆ gmtime()

struct tm * gmtime ( const time_t timep)

Definition at line 164 of file time.c.

165{
166 static struct tm tm;
167 return gmtime_r(timep, &tm);
168}
struct tm * gmtime_r(const time_t *timep, struct tm *tm)
Definition: time.c:108
Here is the call graph for this function:

◆ gmtime_r()

struct tm * gmtime_r ( const time_t timep,
struct tm result 
)

Definition at line 108 of file time.c.

109{
110 uint64_t secs, mins, hours;
111 uint64_t days;
112 uint64_t y, m;
113
114 // Compute seconds
115 secs = *timep % (60 * 60 * 24);
116 days = *timep / (60 * 60 * 24);
117 mins = secs / 60;
118 secs = secs % 60;
119
120 // Compute minutes
121 hours = mins / 60;
122 mins = mins % 60;
123
124 // Compute hours
125 hours = hours % 24;
126
127 tm->tm_sec = secs;
128 tm->tm_min = mins;
129 tm->tm_hour = hours;
130
131 tm->tm_wday = (days + 3) % 7;
132
133 for (y = 1970; ; y++) {
134 uint64_t daysOfYear;
135 if (Time_IsLeapYear(y)) {
136 daysOfYear = 366;
137 } else {
138 daysOfYear = 365;
139 }
140
141 if (days < daysOfYear) {
142 tm->tm_yday = days;
143 tm->tm_year = y - 1900;
144 break;
145 }
146 days -= daysOfYear;
147 }
148
149 for (m = 0; ; m++) {
150 uint64_t daysOfMonth = Time_DaysInMonth(tm->tm_year + 1900, m);
151
152 if (days < daysOfMonth) {
153 tm->tm_mday = days;
154 tm->tm_mon = m;
155 break;
156 }
157 days -= daysOfMonth;
158 }
159
160 return tm;
161}
int tm_yday
Definition: time.h:15
static int Time_DaysInMonth(uint64_t year, uint64_t month)
Definition: time.c:96
static bool Time_IsLeapYear(uint64_t year)
Definition: time.c:84
unsigned long uint64_t
Definition: types.h:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ localtime()

struct tm * localtime ( const time_t timep)

Definition at line 178 of file time.c.

179{
180 static struct tm tm;
181 return localtime_r(timep, &tm);
182}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ localtime_r()

struct tm * localtime_r ( const time_t timep,
struct tm result 
)

Definition at line 171 of file time.c.

172{
173 time_t t = *timep - TZ_OFFSET_SECS;
174 return gmtime_r(&t, result);
175}
#define TZ_OFFSET_SECS
Definition: time.c:11
uint64_t time_t
Definition: types.h:25
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mktime()

time_t mktime ( struct tm tm)

Definition at line 185 of file time.c.

186{
187 uint64_t days = 0;
188 uint64_t secs = 0;
189 uint64_t y, m;
190
191 // Convert to UNIX epoch
192 for (y = 70; y < tm->tm_year; y++) {
193 if (Time_IsLeapYear(y))
194 days += 366;
195 else
196 days += 365;
197 }
198
199 uint64_t yday = 0;
200 for (m = 0; m < tm->tm_mon; m++) {
201 yday += Time_DaysInMonth(tm->tm_year + 1900, m);
202 }
203 yday += tm->tm_mday;
204 days += yday;
205
206 secs = 24 * days + tm->tm_hour;
207 secs = secs * 60 + tm->tm_min;
208 secs = secs * 60 + tm->tm_sec;
209
210 secs += TZ_OFFSET_SECS;
211
212 return secs;
213}
Here is the call graph for this function:

◆ time()

time_t time ( time_t t)

Definition at line 20 of file time.c.

21{
22 uint64_t nsec = OSTime();
23 time_t sec = nsec / 1000000000;
24
25 if (t)
26 *t = sec;
27
28 return sec;
29}
uint64_t OSTime()
Definition: syscall.c:11
Here is the call graph for this function:
Here is the caller graph for this function: