Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: Patrick Steinhardt <ps@pks.im>,
	 git@vger.kernel.org,  Josh McKinney <git-bugs@lists.joshka.net>
Subject: Re: [PATCH 1/3] date: add helpers to convert between "+HHMM" timezones and minutes
Date: Wed, 30 Sep 2026 12:54:26 -0700	[thread overview]
Message-ID: <xmqqa4oya51p.fsf@gitster.g> (raw)
In-Reply-To: <CAOLa=ZQRDVL2Djh4du1zWGg_ABZTyzaWDYYb0PDg3EXAfpn7bA@mail.gmail.com> (Karthik Nayak's message of "Wed, 30 Sep 2026 04:47:02 -0700")

Karthik Nayak <karthik.188@gmail.com> writes:

>> -	int minutes;
>> +	int minutes = tz < 0 ? -tz : tz;
>
> This is the part which we could skip as we're C99 compliant, but keeping
> to be on the safe side.
>
>> +	minutes = (minutes / 100) * 60 + (minutes % 100);
>> +	return tz < 0 ? -minutes : minutes;
>> +}

I was wondering exactly the same thing yesterday.

As written, it is clear even to those unfamiliar with the C89/C99
signed division rules, because we deal only with non-negative
numbers, which is a plus.  The fewer things readers need to worry
about, the better.


>>  	offset /= 60; /* in minutes */
>> -	offset = (offset % 60) + ((offset / 60) * 100);
>> -	return offset * eastwest;
>> +	return minutes_to_tz(offset * eastwest);
>
> While mathematically it's the same, but shouldn't this have been
> `minutes_to_tz(offset) * eastwest`?

The way you suggest is more faithful rewrite of the original.

Thanks.

  parent reply	other threads:[~2026-09-30 19:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  9:56 [PATCH 0/3] refs/reftable: fix on-disk representation of reflog timezones Patrick Steinhardt
2026-09-29  9:56 ` [PATCH 1/3] date: add helpers to convert between "+HHMM" timezones and minutes Patrick Steinhardt
2026-09-30 11:47   ` Karthik Nayak
2026-09-30 12:05     ` Patrick Steinhardt
2026-10-01 10:18       ` Karthik Nayak
2026-09-30 19:54     ` Junio C Hamano [this message]
2026-09-29  9:56 ` [PATCH 2/3] t/helper: fix segfault in "dump-reftable -t" Patrick Steinhardt
2026-09-29  9:56 ` [PATCH 3/3] refs/reftable: fix on-disk representation of reflog timezones Patrick Steinhardt
2026-09-30 11:51   ` Karthik Nayak
2026-09-30 12:05     ` Patrick Steinhardt
2026-10-01  5:38 ` [PATCH v2 0/3] " Patrick Steinhardt
2026-10-01  5:39   ` [PATCH v2 1/3] date: add helpers to convert between "+HHMM" timezones and minutes Patrick Steinhardt
2026-10-01  5:39   ` [PATCH v2 2/3] t/helper: fix segfault in "dump-reftable -t" Patrick Steinhardt
2026-10-01  5:39   ` [PATCH v2 3/3] refs/reftable: fix on-disk representation of reflog timezones Patrick Steinhardt
2026-10-01 10:19   ` [PATCH v2 0/3] " Karthik Nayak
2026-10-01 17:11     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqa4oya51p.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git-bugs@lists.joshka.net \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox