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

[PATCH 1/1] Fix date checking in case if time was not initialized.

From
Mike Gorchak <mike.gorchak.qnx@gmail.com>
Date
Feb 25, 2013, 08:36 UTC
Message-ID
<CAHXAxrOOqn6ZSVT1AFyO3a3paD1tokBtcnaX68a+ddhodOvZ6Q@mail.gmail.com>

Fix is_date() function failings in detection of correct date in case if time was not properly initialized.

From: Mike Gorchak <mike.gorchak.qnx@gmail.com>
Signed-off-by: Mike Gorchak <mike.gorchak.qnx@gmail.com>
---
 date.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/date.c b/date.c
index 57331ed..ec758f4 100644
--- a/date.c
+++ b/date.c
@@ -357,6 +357,7 @@ static int is_date(int year, int month, int day,
struct tm *now_tm, time_t now,
 	if (month > 0 && month < 13 && day > 0 && day < 32) {
 		struct tm check = *tm;
 		struct tm *r = (now_tm ? &check : tm);
+		struct tm fixed_r;
 		time_t specified;

 		r->tm_mon = month - 1;
@@ -377,7 +378,16 @@ static int is_date(int year, int month, int day,
struct tm *now_tm, time_t now,
 		if (!now_tm)
 			return 1;

-		specified = tm_to_time_t(r);
+		/* Fix tm structure in case if time was not initialized */
+		fixed_r = *r;
+		if (fixed_r.tm_hour==-1)
+			fixed_r.tm_hour=0;
+		if (fixed_r.tm_min==-1)
+			fixed_r.tm_min=0;
+		if (fixed_r.tm_sec==-1)
+			fixed_r.tm_sec=0;
+
+		specified = tm_to_time_t(&fixed_r);

 		/* Be it commit time or author time, it does not make
 		 * sense to specify timestamp way into the future.  Make
-- 
1.8.2-rc0
Next: Junio C Hamano
Message 1 of 9 in “Fix date checking in case if time was not initialized.”
  1. 1/1 Fix date checking in case if time was not initialized.Mike Gorchak, Feb 25, 2013
  2. Junio C HamanoFeb 25, 2013
  3. Mike GorchakFeb 25, 2013
  4. Junio C HamanoFeb 25, 2013
  5. Mike GorchakFeb 25, 2013
  6. Junio C HamanoFeb 25, 2013
  7. Mike GorchakFeb 25, 2013
  8. Junio C HamanoFeb 25, 2013
  9. Mike GorchakFeb 26, 2013

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.