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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 4, 2010 at 06:48 UTC
6b097788f88a29d6e171af7a9e87117cf992e833
2 files changed
+9
-5
t/t0006-date.sh
+3
-2
@@ -28,8 +28,8 @@ check_show 31449600 '12 months ago'
28
29
check_parse() {
30
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 &&
33
test_cmp expect actual
34
"
35
}
@@ -38,6 +38,7 @@ check_parse 2008 bad
38
check_parse 2008-02 bad
39
check_parse 2008-02-14 bad
40
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'
42
43
check_approxidate() {
44
echo "$1 -> $2 +0000" >expect
test-date.c
+6
-3
@@ -21,12 +21,15 @@ static void parse_dates(char **argv, struct timeval *now)
21
for (; *argv; argv++) {
22
char result[100];
23
time_t t;
24
+ int tz;
25
26
result[0] = 0;
27
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);
33
}
34
}
35