From: Andre Noll <maan@tuebingen.mpg.de>
Date: Sat, 5 Sep 2015 17:51:28 +0000 (+0200)
Subject: Improve lastplayed time format for ls and stat output.
X-Git-Tag: v0.5.6~90
X-Git-Url: https://git.tue.mpg.de/?a=commitdiff_plain;h=3c978d34b0e9e435c097f3cd6fbabf031087a3b6;p=paraslash.git

Improve lastplayed time format for ls and stat output.

It is possible that the lastplayed time happens to be in the future.

Fix a whitespace issue while at it.
---

diff --git a/aft.c b/aft.c
index 8a8e5282..8df2bc60 100644
--- a/aft.c
+++ b/aft.c
@@ -677,6 +677,11 @@ static int get_local_time(uint64_t *seconds, char *buf, size_t size,
 	time_t current_time, enum ls_listing_mode lm)
 {
 	struct tm t;
+	/*
+	 * Omit year but show time if the given value is closer to the current
+	 * time than this many seconds.
+	 */
+	const time_t m = 6 * 30 * 24 * 3600; /* six months */
 
 	if (!localtime_r((time_t *)seconds, &t))
 		return -E_LOCALTIME;
@@ -685,12 +690,12 @@ static int get_local_time(uint64_t *seconds, char *buf, size_t size,
 			return -E_STRFTIME;
 		return 1;
 	}
-	if (*seconds + 6 * 30 * 24 * 3600 > current_time) {
+	if (*seconds > current_time - m && *seconds < current_time + m) {
 		if (!strftime(buf, size, "%b %e %k:%M", &t))
 			return -E_STRFTIME;
 		return 1;
 	}
-	if (!strftime(buf, size, "%b %e  %Y", &t))
+	if (!strftime(buf, size, "%b %e %Y", &t))
 		return -E_STRFTIME;
 	return 1;
 }