eb6ddac1eb
Apparently gmtime was already implemented when I made localtime, so we had two different things written from scratch. We decided in the relibc channel of the Redox OS Mattermost chat to use my code, as it is more extensively tested and perhaps is clearer in how it works.
19 lines
586 B
C
19 lines
586 B
C
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
int main() {
|
|
int day = 60 * 60 * 24;
|
|
time_t inputs[] = { -(day * 33), -day, -1, -500, 0, 1, 1531454950 };
|
|
for (int i = 0; i < (sizeof(inputs) / sizeof(time_t)); i += 1) {
|
|
struct tm* t = localtime(&inputs[i]);
|
|
|
|
printf(
|
|
"Year %d, Day of year: %d, Month %d, Day of month: %d, Day of week: %d, %d:%d:%d\n",
|
|
t->tm_year, t->tm_yday, t->tm_mon, t->tm_mday, t->tm_wday, t->tm_hour, t->tm_min, t->tm_sec
|
|
);
|
|
}
|
|
|
|
time_t input = 1531461823;
|
|
fputs(ctime(&input), stdout); // Omit newline
|
|
}
|