Skip to content

Improve test_strptime_days. NFC #21037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions test/core/test_strptime_days.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* found in the LICENSE file.
*/

// glibc requires _XOPEN_SOURCE to be defined in order to get strptime.
#define _XOPEN_SOURCE

#include <assert.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -31,9 +35,14 @@ int main() {
for (int i = 0; i < sizeof(day_tests) / sizeof(day_tests[0]); ++i) {
memset(&tm, '\0', sizeof(tm));
char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm);
assert(ptr);

printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n",
(ptr != NULL && *ptr == '\0') ? "OK" : "ERR", tm.tm_mon + 1,
tm.tm_mday, 1900 + tm.tm_year, tm.tm_wday, tm.tm_yday);
printf("%-23s -> %02d/%02d/%4d (%dth DoW, %3dth DoY)\n",
day_tests[i].input,
tm.tm_mon + 1,
tm.tm_mday,
1900 + tm.tm_year,
tm.tm_wday,
tm.tm_yday);
}
}
24 changes: 12 additions & 12 deletions test/core/test_strptime_days.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
OK: 1/1/2000 (6th DoW, 0th DoY)
OK: 3/3/2000 (5th DoW, 62th DoY)
OK: 9/9/1999 (4th DoW, 251th DoY)
OK: 5/2/1999 (0th DoW, 121th DoY)
OK: 5/21/2001 (1th DoW, 140th DoY)
OK: 1/27/2006 (5th DoW, 26th DoY)
OK: 5/21/2001 (1th DoW, 140th DoY)
OK: 7/24/2013 (3th DoW, 204th DoY)
OK: 1/1/2000 (6th DoW, 0th DoY)
OK: 1/1/2000 (6th DoW, 0th DoY)
OK: 5/1/2001 (2th DoW, 120th DoY)
OK: 2/22/2001 (4th DoW, 52th DoY)
2000-01-01 -> 01/01/2000 (6th DoW, 0th DoY)
03/03/00 -> 03/03/2000 (5th DoW, 62th DoY)
9/9/99 -> 09/09/1999 (4th DoW, 251th DoY)
19990502123412 -> 05/02/1999 (0th DoW, 121th DoY)
2001 20 Mon -> 05/21/2001 (1th DoW, 140th DoY)
2006 4 Fri -> 01/27/2006 (5th DoW, 26th DoY)
2001 21 Mon -> 05/21/2001 (1th DoW, 140th DoY)
2013 29 Wed -> 07/24/2013 (3th DoW, 204th DoY)
2000-01-01 08:12:21 AM -> 01/01/2000 (6th DoW, 0th DoY)
2000-01-01 08:12:21 PM -> 01/01/2000 (6th DoW, 0th DoY)
2001 17 Tue -> 05/01/2001 (2th DoW, 120th DoY)
2001 8 Thursday -> 02/22/2001 (4th DoW, 52th DoY)