Skip to content

Commit 1b4d995

Browse files
committed
Merge branch 'ls/doc-raw-timestamp-prefix' into jch
Documentation and tests have been added to clarify that Git's internal raw timestamp format requires a `@` prefix for values less than 100,000,000 to prevent ambiguity with other formats like YYYYMMDD. * ls/doc-raw-timestamp-prefix: doc: document and test `@` prefix for raw timestamps
2 parents 896ce05 + 4018dc2 commit 1b4d995

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'
@@ -237,6 +244,10 @@ check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00'
237244
check_approxidate '2008-12-01' '2008-12-01 19:20:00'
238245
check_approxidate '2009-12-01' '2009-12-01 19:20:00'
239246

247+
# ambiguous raw timestamp
248+
check_approxidate '2000 +0000' '2000-08-30 19:20:00'
249+
check_approxidate '@2000 +0000' '1970-01-01 00:33:20'
250+
240251
check_date_format_human() {
241252
t=$(($GIT_TEST_DATE_NOW - $1))
242253
echo "$t -> $2" >expect

0 commit comments

Comments
 (0)