bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

commit 2d7323b8b74bdad6119b99d75909757e6deb30e4
parent 6aa66f03b1bb8a7bc21d14341c3460a85df3ae58
Author: phoebos <ben@bvnf.space>
Date:   Fri,  1 Jul 2022 02:32:44 +0100

ls: print years for dates >6 months ago or in future

Diffstat:
Mls.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/ls.c b/ls.c @@ -171,9 +171,17 @@ printname(struct ent *e) { fprintf(stderr, "ls: %s: %s\n", e->name, strerror(errno)); return 1; } - char buf[sizeof "MMM DD HH:MM"]; - strftime(buf, sizeof(buf), "%b %e %H:%M", tm); - printf("%s ", buf); + time_t time_now = time(NULL); + time_t six_months = time_now - 6*30*24*3600; + if (e->tim.tv_sec < six_months || e->tim.tv_sec > time_now) { + char buf[sizeof "MMM DD YYYY"]; + strftime(buf, sizeof(buf), "%b %e %Y", tm); + printf("%s ", buf); + } else { + char buf[sizeof "MMM DD HH:MM"]; + strftime(buf, sizeof(buf), "%b %e %H:%M", tm); + printf("%s ", buf); + } } qprint(e->name, flags & FLAG_q);