Don't assume that the output of strftime for "%c" ("national
representation of time and date") won't change in time. Instead of hard coding the locations of the time elements and hoping that they don't move use strftime to generate the desired formats in the first place. PR: bin/7826
This commit is contained in:
parent
6019e6208f
commit
97e4e97bd1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=61814
@ -293,30 +293,25 @@ static void
|
||||
printtime(ftime)
|
||||
time_t ftime;
|
||||
{
|
||||
int i;
|
||||
char longstring[80];
|
||||
static time_t now;
|
||||
const char *format;
|
||||
|
||||
if (now == 0)
|
||||
now = time(NULL);
|
||||
|
||||
strftime(longstring, sizeof(longstring), "%c", localtime(&ftime));
|
||||
for (i = 4; i < 11; ++i)
|
||||
(void)putchar(longstring[i]);
|
||||
|
||||
#define SIXMONTHS ((365 / 2) * 86400)
|
||||
if (f_sectime)
|
||||
for (i = 11; i < 24; i++)
|
||||
(void)putchar(longstring[i]);
|
||||
/* Mmm dd hh:mm:ss yyyy */
|
||||
format = "%b %e %T %Y ";
|
||||
else if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS)
|
||||
for (i = 11; i < 16; ++i)
|
||||
(void)putchar(longstring[i]);
|
||||
else {
|
||||
(void)putchar(' ');
|
||||
for (i = 20; i < 24; ++i)
|
||||
(void)putchar(longstring[i]);
|
||||
}
|
||||
(void)putchar(' ');
|
||||
/* Mmm dd hh:mm */
|
||||
format = "%b %e %R ";
|
||||
else
|
||||
/* Mmm dd yyyy */
|
||||
format = "%b %e %Y ";
|
||||
strftime(longstring, sizeof(longstring), format, localtime(&ftime));
|
||||
fputs(longstring, stdout);
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
Reference in New Issue
Block a user