All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] date.c: print "1 second ago", not "1 seconds ago"
@ 2010-04-21  5:31 Øyvind A. Holm
  2010-04-21  6:13 ` Johannes Sixt
  0 siblings, 1 reply; 4+ messages in thread
From: Øyvind A. Holm @ 2010-04-21  5:31 UTC (permalink / raw)
  To: git; +Cc: Øyvind A. Holm

When using --date=relative, print "1 second ago" instead of "1 seconds
ago".

t0006: Add tests for 0, 1 and 2 seconds ago, to ensure that
--date=relative prints "1 second ago" and "x seconds ago" when x != 1.

Signed-off-by: Øyvind A. Holm <sunny@sunbase.org>
---
 date.c          |    3 ++-
 t/t0006-date.sh |    4 ++++
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/date.c b/date.c
index 002aa3c..6aec22b 100644
--- a/date.c
+++ b/date.c
@@ -96,7 +96,8 @@ const char *show_date_relative(unsigned long time, int tz,
 		return "in the future";
 	diff = now->tv_sec - time;
 	if (diff < 90) {
-		snprintf(timebuf, timebuf_size, "%lu seconds ago", diff);
+		snprintf(timebuf, timebuf_size, "%lu second%s ago",
+				diff, (diff != 1 ? "s" : ""));
 		return timebuf;
 	}
 	/* Turn it into minutes */
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 75b02af..3069545 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -15,6 +15,9 @@ check_show() {
 	"
 }
 
+check_show 0 '0 seconds ago'
+check_show 1 '1 second ago'
+check_show 2 '2 seconds ago'
 check_show 5 '5 seconds ago'
 check_show 300 '5 minutes ago'
 check_show 18000 '5 hours ago'
@@ -48,6 +51,7 @@ check_approxidate() {
 }
 
 check_approxidate now '2009-08-30 19:20:00'
+check_approxidate '1 second ago' '2009-08-30 19:19:59'
 check_approxidate '5 seconds ago' '2009-08-30 19:19:55'
 check_approxidate 5.seconds.ago '2009-08-30 19:19:55'
 check_approxidate 10.minutes.ago '2009-08-30 19:10:00'
-- 
1.7.1.rc2.5.gddd02

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

* Re: [PATCH] date.c: print "1 second ago", not "1 seconds ago"
  2010-04-21  5:31 [PATCH] date.c: print "1 second ago", not "1 seconds ago" Øyvind A. Holm
@ 2010-04-21  6:13 ` Johannes Sixt
  2010-04-21  6:28   ` Øyvind A. Holm
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2010-04-21  6:13 UTC (permalink / raw)
  To: "Øyvind A. Holm"; +Cc: git

Am 4/21/2010 7:31, schrieb Øyvind A. Holm:
> When using --date=relative, print "1 second ago" instead of "1 seconds
> ago".

Why do you care only about about "1 seconds", but not "1 minutes", "1
hours", etc? I mean, "1 seconds ago" is the most unlikely case of them all
that will happen in practice...

-- Hannes

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

* Re: [PATCH] date.c: print "1 second ago", not "1 seconds ago"
  2010-04-21  6:13 ` Johannes Sixt
@ 2010-04-21  6:28   ` Øyvind A. Holm
  2010-04-21  6:35     ` Johannes Sixt
  0 siblings, 1 reply; 4+ messages in thread
From: Øyvind A. Holm @ 2010-04-21  6:28 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

On 21 April 2010 08:13, Johannes Sixt <j.sixt@viscovery.net> wrote:
> Am 4/21/2010 7:31, schrieb Øyvind A. Holm:
>> When using --date=relative, print "1 second ago" instead of "1 seconds
>> ago".
>
> Why do you care only about about "1 seconds", but not "1 minutes", "1
> hours", etc? I mean, "1 seconds ago" is the most unlikely case of them all
> that will happen in practice...

It will never show "1 minute", "1 hour", etc. Only

  - "89 minutes" → "2 hours"
  - "35 hours" → "2 days"
  - "13 days" → "2 weeks"

and so on. Seconds is the only thing left to fix.

Cheers,
Øyvind A. Holm
(sunny256)

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

* Re: [PATCH] date.c: print "1 second ago", not "1 seconds ago"
  2010-04-21  6:28   ` Øyvind A. Holm
@ 2010-04-21  6:35     ` Johannes Sixt
  0 siblings, 0 replies; 4+ messages in thread
From: Johannes Sixt @ 2010-04-21  6:35 UTC (permalink / raw)
  To: "Øyvind A. Holm"; +Cc: git

Am 4/21/2010 8:28, schrieb Øyvind A. Holm:
> It will never show "1 minute", "1 hour", etc.

I see, thanks.

-- Hannes

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

end of thread, other threads:[~2010-04-21  6:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21  5:31 [PATCH] date.c: print "1 second ago", not "1 seconds ago" Øyvind A. Holm
2010-04-21  6:13 ` Johannes Sixt
2010-04-21  6:28   ` Øyvind A. Holm
2010-04-21  6:35     ` Johannes Sixt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.