# Defining timestamp_t as intmax_t instead of uintmax_t

4 messages from 2025-03-11 to 2025-03-11. Participants: Arnav Bhate, Junio C Hamano.
Thread: https://gitlist.dev/t/63092

## Arnav Bhate, 2025-03-11 10:00

Subject: Defining timestamp_t as intmax_t instead of uintmax_t
Message-ID: <629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com>
URL: https://gitlist.dev/e/629c3c21-ab11-42c1-8cb1-34698e736db6%40gmail.com

```
timestamp_t is a data type defined in git-compat-util.h as uintmax_t since
28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with
dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace
use of both time_t and unsigned long for time-related uses.

On Linux with glibc[1] and on Windows with MSVC[2], time_t is always a signed
type. I think this is also the case on MacOS and FreeBSD. Thus, any conversion
or comparison between the two types is one between a signed and an unsigned
type. This also means git cannot deal with time before 1970, though I can't
think of a scenario where it will have to. However, it does it to sign
compare warnings from the compiler.

I propose swapping uintmax_t with intmax_t to fix this problem. I do not think
that this will cause any problem unless any code sets the most significant bit
of the timestamp for some special purpose. However, the fix will take some
work, considering the number of references to timestamp_t. So I want to get
everyone's opinions on whether this should be done before starting work on it.

[1] https://www.gnu.org/software/libc/manual/html_node/Time-Types.html
[2] https://learn.microsoft.com/en-us/cpp/c-runtime-library/standard-types?view=msvc-170
-- 
Regards,
Arnav Bhate
(He/Him)


```

## Arnav Bhate, 2025-03-11 10:54

Subject: Re: Defining timestamp_t as intmax_t instead of uintmax_t
Message-ID: <65ea4bed-1513-4721-af63-1ebc78194a7d@gmail.com>
URL: https://gitlist.dev/e/65ea4bed-1513-4721-af63-1ebc78194a7d%40gmail.com
In-Reply-To: <629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com>

```
Arnav Bhate <bhatearnav@gmail.com> writes:
> This also means git cannot deal with time before 1970, though I can't
> think of a scenario where it will have to.

I just tested and found that if the user enters dates before 1970 the output is
incorrect, for example with git log. This error also seems to propagate to
GitHub. This may or may not be related to using uintmax_t, however it seems
likely.

-- 
Regards,
Arnav Bhate
(He/Him)


```

## Junio C Hamano, 2025-03-11 17:28

Subject: Re: Defining timestamp_t as intmax_t instead of uintmax_t
Message-ID: <xmqqv7sf32a6.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqv7sf32a6.fsf%40gitster.g
In-Reply-To: <629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com>

```
Arnav Bhate <bhatearnav@gmail.com> writes:

> timestamp_t is a data type defined in git-compat-util.h as uintmax_t since
> 28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with
> dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace
> use of both time_t and unsigned long for time-related uses.

I do not think the object format and the existing object parsers are
prepared to handle timestamp before the epoch.

You may want to go back to the list archive for discussions around
the choice of the type back then, which should have enough
information to go by.

https://lore.kernel.org/git/20170228200145.ymbqmxwrbbrwagks@sigill.intra.peff.net/

might be a good starting point.

https://lore.kernel.org/git/?q=f:peff@+d:20170201..20170430+timestamp_t

gives 6 entry points to a single large thread that may be worth
following before tackling this topic further.

Thanks.

```

## Arnav Bhate, 2025-03-11 18:23

Subject: Re: Defining timestamp_t as intmax_t instead of uintmax_t
Message-ID: <ab2af3ec-f4cf-4337-82ce-7c4ade244568@gmail.com>
URL: https://gitlist.dev/e/ab2af3ec-f4cf-4337-82ce-7c4ade244568%40gmail.com
In-Reply-To: <xmqqv7sf32a6.fsf@gitster.g>

```
Junio C Hamano <gitster@pobox.com> writes:
> Arnav Bhate <bhatearnav@gmail.com> writes:
> 
>> timestamp_t is a data type defined in git-compat-util.h as uintmax_t since
>> 28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with
>> dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace
>> use of both time_t and unsigned long for time-related uses.
> 
> I do not think the object format and the existing object parsers are
> prepared to handle timestamp before the epoch.

Looks like I bit off more than I could chew. Maybe this could be a medium-sized
project in itself.

> You may want to go back to the list archive for discussions around
> the choice of the type back then, which should have enough
> information to go by.
> 
> https://lore.kernel.org/git/20170228200145.ymbqmxwrbbrwagks@sigill.intra.peff.net/
> 
> might be a good starting point.
> 
> https://lore.kernel.org/git/?q=f:peff@+d:20170201..20170430+timestamp_t
> 
> gives 6 entry points to a single large thread that may be worth
> following before tackling this topic further.
> 
> Thanks.

I'll go through it.

-- 
Regards,
Arnav Bhate
(He/Him)


```
