From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] date: remove approxidate_relative()
Date: Sat, 8 Apr 2023 11:35:24 +0200 [thread overview]
Message-ID: <f5b9a290-7cec-7a83-660b-e15494d2cdc8@web.de> (raw)
When 29f4332e66 (Quit passing 'now' to date code, 2019-09-11) removed
its timeval parameter, approxidate_relative() became equivalent to
approxidate(). Convert its last two call sites and remove the redundant
function.
Signed-off-by: René Scharfe <l.s.r@web.de>
---
Formatted with -U16 for easier review. Only useful in date.c, but
cannot be restricted to just one file.
date.c | 14 --------------
date.h | 1 -
t/helper/test-date.c | 4 ++--
3 files changed, 2 insertions(+), 17 deletions(-)
diff --git a/date.c b/date.c
index 1fb2cd1b53..7c8650f799 100644
--- a/date.c
+++ b/date.c
@@ -1353,46 +1353,32 @@ static timestamp_t approxidate_str(const char *date,
date++;
if (isdigit(c)) {
pending_number(&tm, &number);
date = approxidate_digit(date-1, &tm, &number, time_sec);
touched = 1;
continue;
}
if (isalpha(c))
date = approxidate_alpha(date-1, &tm, &now, &number, &touched);
}
pending_number(&tm, &number);
if (!touched)
*error_ret = 1;
return (timestamp_t)update_tm(&tm, &now, 0);
}
-timestamp_t approxidate_relative(const char *date)
-{
- struct timeval tv;
- timestamp_t timestamp;
- int offset;
- int errors = 0;
-
- if (!parse_date_basic(date, ×tamp, &offset))
- return timestamp;
-
- get_time(&tv);
- return approxidate_str(date, (const struct timeval *) &tv, &errors);
-}
-
timestamp_t approxidate_careful(const char *date, int *error_ret)
{
struct timeval tv;
timestamp_t timestamp;
int offset;
int dummy = 0;
if (!error_ret)
error_ret = &dummy;
if (!parse_date_basic(date, ×tamp, &offset)) {
*error_ret = 0;
return timestamp;
}
get_time(&tv);
return approxidate_str(date, &tv, error_ret);
diff --git a/date.h b/date.h
index 5d4eaba0a9..6136212a19 100644
--- a/date.h
+++ b/date.h
@@ -55,20 +55,19 @@ const char *show_date(timestamp_t time, int timezone, const struct date_mode *mo
*/
void parse_date_format(const char *format, struct date_mode *mode);
/**
* Release a "struct date_mode", currently only required if
* parse_date_format() has parsed a "DATE_STRFTIME" format.
*/
void date_mode_release(struct date_mode *mode);
void show_date_relative(timestamp_t time, struct strbuf *timebuf);
int parse_date(const char *date, struct strbuf *out);
int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
int parse_expiry_date(const char *date, timestamp_t *timestamp);
void datestamp(struct strbuf *out);
#define approxidate(s) approxidate_careful((s), NULL)
timestamp_t approxidate_careful(const char *, int *);
-timestamp_t approxidate_relative(const char *date);
int date_overflows(timestamp_t date);
time_t tm_to_time_t(const struct tm *tm);
#endif
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index cd6a6df702..2d9232cc68 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -68,42 +68,42 @@ static void parse_dates(const char **argv)
strbuf_reset(&result);
parse_date(*argv, &result);
if (sscanf(result.buf, "%"PRItime" %d", &t, &tz) == 2)
printf("%s -> %s\n",
*argv, show_date(t, tz, DATE_MODE(ISO8601)));
else
printf("%s -> bad\n", *argv);
}
strbuf_release(&result);
}
static void parse_approxidate(const char **argv)
{
for (; *argv; argv++) {
timestamp_t t;
- t = approxidate_relative(*argv);
+ t = approxidate(*argv);
printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601)));
}
}
static void parse_approx_timestamp(const char **argv)
{
for (; *argv; argv++) {
timestamp_t t;
- t = approxidate_relative(*argv);
+ t = approxidate(*argv);
printf("%s -> %"PRItime"\n", *argv, t);
}
}
static void getnanos(const char **argv)
{
double seconds = getnanotime() / 1.0e9;
if (*argv)
seconds -= strtod(*argv, NULL);
printf("%lf\n", seconds);
}
int cmd__date(int argc UNUSED, const char **argv)
{
const char *x;
--
2.40.0
next reply other threads:[~2023-04-08 9:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-08 9:35 René Scharfe [this message]
2023-04-10 16:20 ` [PATCH] date: remove approxidate_relative() Junio C Hamano
2023-04-10 20:25 ` Jeff King
2023-04-10 20:52 ` René Scharfe
2023-04-11 9:25 ` Jeff King
2023-04-10 21:05 ` Junio C Hamano
2023-04-11 9:30 ` Jeff King
2023-04-11 15:43 ` Junio C Hamano
2023-04-12 7:30 ` Jeff King
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=f5b9a290-7cec-7a83-660b-e15494d2cdc8@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).