Skip to content

Commit 4018dc2

Browse files
lunaglgitster
andcommitted
doc: document and test @ prefix for raw timestamps
The Git internal date format `<unix-timestamp> <time-zone-offset>` fails to parse when the timestamp is less than 100,000,000 (fewer than 9 digits). This happens to avoid potential ambiguity with other date formats such as `YYYYMMDD`, especially when used with approxidate. To force the parser to interpret the value as a raw timestamp, it must be prefixed with `@` (e.g., `@0 +0000`). This behavior was introduced in 2c733fb (parse_date(): '@' prefix forces git-timestamp, 2012-02-02) but was never documented. Document the `@` prefix in `Documentation/date-formats.adoc` to make this behavior explicit. Also add test cases to `t/t0006-date.sh` to verify and demonstrate the difference between prefixed and unprefixed small timestamps (e.g., `@2000` vs `2000`). Signed-off-by: Luna Schwalbe <dev@luna.gl> Co-authored-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 67ad421 commit 4018dc2

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Documentation/date-formats.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Git internal format::
99
`<unix-timestamp>` is the number of seconds since the UNIX epoch.
1010
`<time-zone-offset>` is a positive or negative offset from UTC.
1111
For example CET (which is 1 hour ahead of UTC) is `+0100`.
12+
+
13+
It is safer to prepend the `<unix-timestamp>` with `@` (e.g.,
14+
`@0 +0000`), which forces Git to interpret it as a raw timestamp. This
15+
is required for values less than 100,000,000 (which have fewer than 9
16+
digits) to avoid confusion with other date formats like `YYYYMMDD`.
1217

1318
RFC 2822::
1419
The standard date format as described by RFC 2822, for example

t/t0006-date.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ check_parse '1969-12-31 23:59:59 Z' bad
138138
check_parse '1969-12-31 23:59:59 +11' bad
139139
check_parse '1969-12-31 23:59:59 -11' bad
140140

141+
# pathologically small timestamps requiring `@` prefix
142+
check_parse '@0 +0000' '1970-01-01 00:00:00 +0000'
143+
check_parse '@99999999 +0000' '1973-03-03 09:46:39 +0000'
144+
check_parse '99999999 +0000' bad
145+
check_parse '@100000000 +0000' '1973-03-03 09:46:40 +0000'
146+
check_parse '100000000 +0000' '1973-03-03 09:46:40 +0000'
147+
141148
REQUIRE_64BIT_TIME=HAVE_64BIT_TIME
142149
check_parse '2099-12-31 23:59:59' '2099-12-31 23:59:59 +0000'
143150
check_parse '2099-12-31 23:59:59 +00' '2099-12-31 23:59:59 +0000'
@@ -195,6 +202,10 @@ check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00'
195202
check_approxidate '2008-12-01' '2008-12-01 19:20:00'
196203
check_approxidate '2009-12-01' '2009-12-01 19:20:00'
197204

205+
# ambiguous raw timestamp
206+
check_approxidate '2000 +0000' '2000-08-30 19:20:00'
207+
check_approxidate '@2000 +0000' '1970-01-01 00:33:20'
208+
198209
check_date_format_human() {
199210
t=$(($GIT_TEST_DATE_NOW - $1))
200211
echo "$t -> $2" >expect

0 commit comments

Comments
 (0)