forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix localtime() and gmtime() with 64bit time_t
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2022 The Emscripten Authors. All rights reserved. | ||
* Emscripten is available under two separate licenses, the MIT license and the | ||
* University of Illinois/NCSA Open Source License. Both these licenses can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <time.h> | ||
#include <stdio.h> | ||
|
||
void | ||
print_time(time_t time) | ||
{ | ||
char gmbuf[32], locbuf[32]; | ||
const char fmt[] = "%Y-%m-%d %H:%M:%S"; | ||
struct tm *gm; | ||
struct tm *loc; | ||
|
||
gm = gmtime(&time); | ||
assert(strftime(gmbuf, sizeof(gmbuf) - 1, fmt, gm) > 0); | ||
loc = localtime(&time); | ||
assert(strftime(locbuf, sizeof(locbuf) - 1, fmt, loc) > 0); | ||
printf("time: %lld, gmtime: %s, localtime: %s\n", time, gmbuf, locbuf); | ||
} | ||
|
||
int main() { | ||
// test assumes EST+05 | ||
print_time(0); | ||
print_time(2147483647); // int8_t max, Y2K38 | ||
print_time(2147483648); | ||
print_time(-2147483648); // int8_t min | ||
print_time(-2147483649); | ||
print_time(253402300799); | ||
print_time(-62135596800 + 5 * 3600); | ||
puts("success"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
time: 0, gmtime: 1970-01-01 00:00:00, localtime: 1969-12-31 19:00:00 | ||
time: 2147483647, gmtime: 2038-01-19 03:14:07, localtime: 2038-01-18 22:14:07 | ||
time: 2147483648, gmtime: 2038-01-19 03:14:08, localtime: 2038-01-18 22:14:08 | ||
time: -2147483648, gmtime: 1901-12-13 20:45:52, localtime: 1901-12-13 15:45:52 | ||
time: -2147483649, gmtime: 1901-12-13 20:45:51, localtime: 1901-12-13 15:45:51 | ||
time: 253402300799, gmtime: 9999-12-31 23:59:59, localtime: 9999-12-31 18:59:59 | ||
time: -62135578800, gmtime: 1-01-01 05:00:00, localtime: 1-01-01 00:00:00 | ||
success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters