From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 1/2] tm_to_time_t(): allow times in year 1969
Date: Fri, 10 Jul 2009 20:20:06 -0700 [thread overview]
Message-ID: <7vfxd3rjmh.fsf_-_@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7vk52frjv9.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Fri\, 10 Jul 2009 20\:14\:50 -0700")
We used to reject anything older than January 1st 1970 regardless of the
timezone, but in order to parse UNIX epoch in zones west of GMT, we need
to allow the time without zone to be a little bit into 1969.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
date.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/date.c b/date.c
index 409a17d..5d259af 100644
--- a/date.c
+++ b/date.c
@@ -6,6 +6,7 @@
#include "cache.h"
+#define BAD_STRUCT_TM (-400*24*60*60)
/*
* This is like mktime, but without normalization of tm_wday and tm_yday.
*/
@@ -18,10 +19,10 @@ time_t tm_to_time_t(const struct tm *tm)
int month = tm->tm_mon;
int day = tm->tm_mday;
- if (year < 0 || year > 129) /* algo only works for 1970-2099 */
- return -1;
+ if (year < -1 || year > 129) /* algo only works for 1969-2099 */
+ return BAD_STRUCT_TM;
if (month < 0 || month > 11) /* array bounds */
- return -1;
+ return BAD_STRUCT_TM;
if (month < 2 || (year + 2) % 4)
day--;
return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL +
@@ -337,7 +338,7 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
return 1;
r->tm_year = now_tm->tm_year;
}
- else if (year >= 1970 && year < 2100)
+ else if (year >= 1969 && year < 2100)
r->tm_year = year - 1900;
else if (year > 70 && year < 100)
r->tm_year = year;
@@ -611,12 +612,11 @@ int parse_date(const char *date, char *result, int maxlen)
/* mktime uses local timezone */
then = tm_to_time_t(&tm);
- if (offset == -1)
- offset = (then - mktime(&tm)) / 60;
-
- if (then == -1)
+ if (then == BAD_STRUCT_TM)
return -1;
+ if (offset == -1)
+ offset = (then - mktime(&tm)) / 60;
if (!tm_gmt)
then -= offset * 60;
return date_string(then, offset, result, maxlen);
--
1.6.3.3.412.gf581d
next prev parent reply other threads:[~2009-07-11 3:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4A5680B5.2090405@necel.com>
[not found] ` <4A56B060.7090106@mips.com>
2009-07-10 10:47 ` What's happening with vr41xx_giu.c? Ralf Baechle
2009-07-10 16:20 ` Junio C Hamano
2009-07-11 3:14 ` Junio C Hamano
2009-07-11 3:20 ` Junio C Hamano [this message]
2009-07-11 3:20 ` [PATCH 2/2] apply: notice creation/removal patches produced by GNU diff Junio C Hamano
2009-07-11 3:32 ` Linus Torvalds
2009-07-11 3:57 ` 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=7vfxd3rjmh.fsf_-_@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).