git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] parse_date_basic(): return early when given a bogus timestamp

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 15, 2015, 16:21 UTC
Message-ID
<xmqqa8y9mkfa.fsf_-_@gitster.dls.corp.google.com>
In-Reply-To
<xmqqk2xdmp0e.fsf@gitster.dls.corp.google.com>

When the input does not have GMT timezone offset, the code computes it by computing the local and GMT time for the given timestamp. But there is no point doing so if the given timestamp is known to be a bogus one.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * A simple preliminary clean-up while we are in the vicinity.  We
   may want to use time_t throughout the codepath and turn it into
   ulong at the very last, but that would be a separate topic.
 date.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/date.c b/date.c
index 782de95..01fd73f 100644
--- a/date.c
+++ b/date.c
@@ -696,6 +696,9 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
 
 	/* mktime uses local timezone */
 	*timestamp = tm_to_time_t(&tm);
+	if (*timestamp == -1)
+		return -1;
+
 	if (*offset == -1) {
 		time_t temp_time = mktime(&tm);
 		if ((time_t)*timestamp > temp_time) {
@@ -705,8 +708,6 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
 		}
 	}
 
-	if (*timestamp == -1)
-		return -1;
 
 	if (!tm_gmt)
 		*timestamp -= *offset * 60;
-- 
2.4.0-rc2-165-g862640d
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 10 in “Odd broken "--date=now" behavior in current git”
  1. Linus TorvaldsApr 15, 2015
  2. Junio C HamanoApr 15, 2015
  3. Eric SunshineApr 15, 2015
  4. Junio C HamanoApr 15, 2015
  5. 1/2 parse_date_basic(): return early when given a bogus timestampJunio C Hamano, Apr 15, 2015
  6. 2/2 parse_date_basic(): let the system handle DST conversionJunio C Hamano, Apr 15, 2015
  7. Eric SunshineApr 15, 2015
  8. Linus TorvaldsApr 15, 2015
  9. Junio C HamanoApr 15, 2015
  10. Peter KreftingApr 15, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.