Skip to content

Commit 6b09778

Browse files
peffgitster
authored andcommitted
t0006: test timezone parsing
Previously, test-date simply ignored the parsed timezone and told show_date() to use UTC. Instead, let's print out what we actually parsed. While we're at it, let's make it easy for tests to work in a specific timezone. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2c64034 commit 6b09778

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

t/t0006-date.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ check_show 31449600 '12 months ago'
2828

2929
check_parse() {
3030
echo "$1 -> $2" >expect
31-
test_expect_${3:-success} "parse date ($1)" "
32-
test-date parse '$1' >actual &&
31+
test_expect_${4:-success} "parse date ($1${3:+ TZ=$3})" "
32+
TZ=${3:-$TZ} test-date parse '$1' >actual &&
3333
test_cmp expect actual
3434
"
3535
}
@@ -38,6 +38,7 @@ check_parse 2008 bad
3838
check_parse 2008-02 bad
3939
check_parse 2008-02-14 bad
4040
check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000'
41+
check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500'
4142

4243
check_approxidate() {
4344
echo "$1 -> $2 +0000" >expect

test-date.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ static void parse_dates(char **argv, struct timeval *now)
2121
for (; *argv; argv++) {
2222
char result[100];
2323
time_t t;
24+
int tz;
2425

2526
result[0] = 0;
2627
parse_date(*argv, result, sizeof(result));
27-
t = strtoul(result, NULL, 0);
28-
printf("%s -> %s\n", *argv,
29-
t ? show_date(t, 0, DATE_ISO8601) : "bad");
28+
if (sscanf(result, "%ld %d", &t, &tz) == 2)
29+
printf("%s -> %s\n",
30+
*argv, show_date(t, tz, DATE_ISO8601));
31+
else
32+
printf("%s -> bad\n", *argv);
3033
}
3134
}
3235

0 commit comments

Comments
 (0)