List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix date tooltips in the distant past
@ 2015-08-13 11:24 john
  2015-08-13 11:24 ` [PATCH 1/3] ui-shared: extract date formatting to a function john
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: john @ 2015-08-13 11:24 UTC (permalink / raw)


This addresses an oversight in commit caed6cb (ui-shared: show absolute
time in tooltip for relative dates, 2014-12-20) which missed the case
where we show a short date if a time is too long ago, which should also
show the full date as a tooltip.

The first two patches are preparatory refactoring and the final one is
the point of the series.

John Keeping (3):
  ui-shared: extract date formatting to a function
  ui-shared: use common function in print_rel_date()
  ui-shared: show full date in tooltip if longer ago than max_relative

 ui-shared.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

-- 
2.5.0.466.g9af26fa



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] ui-shared: extract date formatting to a function
  2015-08-13 11:24 [PATCH 0/3] Fix date tooltips in the distant past john
@ 2015-08-13 11:24 ` john
  2015-08-13 11:24 ` [PATCH 2/3] ui-shared: use common function in print_rel_date() john
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: john @ 2015-08-13 11:24 UTC (permalink / raw)


This will allow this code to be common with print_rel_date.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index 6be0c2e..a6d4b65 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -604,19 +604,24 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
 		path[len - 1] = tail;
 }
 
-void cgit_print_date(time_t secs, const char *format, int local_time)
+static const char *fmt_date(time_t secs, const char *format, int local_time)
 {
-	char buf[64];
+	static char buf[64];
 	struct tm *time;
 
 	if (!secs)
-		return;
+		return "";
 	if (local_time)
 		time = localtime(&secs);
 	else
 		time = gmtime(&secs);
 	strftime(buf, sizeof(buf)-1, format, time);
-	html_txt(buf);
+	return buf;
+}
+
+void cgit_print_date(time_t secs, const char *format, int local_time)
+{
+	html_txt(fmt_date(secs, format, local_time));
 }
 
 static void print_rel_date(time_t t, double value,
-- 
2.5.0.466.g9af26fa



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] ui-shared: use common function in print_rel_date()
  2015-08-13 11:24 [PATCH 0/3] Fix date tooltips in the distant past john
  2015-08-13 11:24 ` [PATCH 1/3] ui-shared: extract date formatting to a function john
@ 2015-08-13 11:24 ` john
  2015-08-13 11:24 ` [PATCH 3/3] ui-shared: show full date in tooltip if longer ago than max_relative john
  2015-08-13 13:40 ` [PATCH 0/3] Fix date tooltips in the distant past Jason
  3 siblings, 0 replies; 5+ messages in thread
From: john @ 2015-08-13 11:24 UTC (permalink / raw)


Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index a6d4b65..792f3ee 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -627,17 +627,8 @@ void cgit_print_date(time_t secs, const char *format, int local_time)
 static void print_rel_date(time_t t, double value,
 	const char *class, const char *suffix)
 {
-	char buf[64];
-	struct tm *time;
-
-	if (ctx.cfg.local_time)
-		time = localtime(&t);
-	else
-		time = gmtime(&t);
-	strftime(buf, sizeof(buf) - 1, FMT_LONGDATE, time);
-
 	htmlf("<span class='%s' title='", class);
-	html_attr(buf);
+	html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
 	htmlf("'>%.0f %s</span>", value, suffix);
 }
 
-- 
2.5.0.466.g9af26fa



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] ui-shared: show full date in tooltip if longer ago than max_relative
  2015-08-13 11:24 [PATCH 0/3] Fix date tooltips in the distant past john
  2015-08-13 11:24 ` [PATCH 1/3] ui-shared: extract date formatting to a function john
  2015-08-13 11:24 ` [PATCH 2/3] ui-shared: use common function in print_rel_date() john
@ 2015-08-13 11:24 ` john
  2015-08-13 13:40 ` [PATCH 0/3] Fix date tooltips in the distant past Jason
  3 siblings, 0 replies; 5+ messages in thread
From: john @ 2015-08-13 11:24 UTC (permalink / raw)


Commit caed6cb (ui-shared: show absolute time in tooltip for relative
dates, 2014-12-20) added a toolip when we show a relative time.

However, in some cases we show a short date (that is, the date but not
the time) if an event was sufficiently far in the past and that commit
did not update that case to add the same tooltip.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ui-shared.c b/ui-shared.c
index 792f3ee..57d7336 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -644,7 +644,11 @@ void cgit_print_age(time_t t, time_t max_relative, const char *format)
 		secs = 0;
 
 	if (secs > max_relative && max_relative >= 0) {
+		html("<span title='");
+		html_attr(fmt_date(t, FMT_LONGDATE, ctx.cfg.local_time));
+		html("'>");
 		cgit_print_date(t, format, ctx.cfg.local_time);
+		html("</span>");
 		return;
 	}
 
-- 
2.5.0.466.g9af26fa



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 0/3] Fix date tooltips in the distant past
  2015-08-13 11:24 [PATCH 0/3] Fix date tooltips in the distant past john
                   ` (2 preceding siblings ...)
  2015-08-13 11:24 ` [PATCH 3/3] ui-shared: show full date in tooltip if longer ago than max_relative john
@ 2015-08-13 13:40 ` Jason
  3 siblings, 0 replies; 5+ messages in thread
From: Jason @ 2015-08-13 13:40 UTC (permalink / raw)


Excellent series, thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20150813/72682a11/attachment.html>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-13 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-13 11:24 [PATCH 0/3] Fix date tooltips in the distant past john
2015-08-13 11:24 ` [PATCH 1/3] ui-shared: extract date formatting to a function john
2015-08-13 11:24 ` [PATCH 2/3] ui-shared: use common function in print_rel_date() john
2015-08-13 11:24 ` [PATCH 3/3] ui-shared: show full date in tooltip if longer ago than max_relative john
2015-08-13 13:40 ` [PATCH 0/3] Fix date tooltips in the distant past Jason

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).