Use AM/PM time only when available in locale

This commit is contained in:
ache 2001-03-02 23:11:38 +00:00
parent 0dd010d57f
commit 19fd09ec57
3 changed files with 10 additions and 7 deletions

View File

@ -35,6 +35,8 @@
*/
extern int use_ampm;
struct kinfo_proc;
void pr_attime __P((time_t *, time_t *));
int pr_idle __P((time_t));

View File

@ -50,9 +50,6 @@ static const char rcsid[] =
/*
* pr_attime --
* Print the time since the user logged in.
*
* Note: SCCS forces the bizarre string manipulation, things like
* 8.2 get replaced in the source code.
*/
void
pr_attime(started, now)
@ -77,12 +74,12 @@ pr_attime(started, now)
tm.tm_year != tp.tm_year) {
/* The line below does not take DST into consideration */
/* else if (*now / 86400 != *started / 86400) { */
(void)strcpy(fmt, __CONCAT("%a%", "I%p"));
(void)strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H ");
}
/* Default is hh:mm{am,pm}. */
else {
(void)strcpy(fmt, __CONCAT("%l:%", "M%p"));
(void)strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M ");
}
(void)strftime(buf, sizeof(buf) - 1, fmt, &tp);

View File

@ -70,6 +70,8 @@ static const char rcsid[] =
#include <errno.h>
#include <fcntl.h>
#include <kvm.h>
#include <langinfo.h>
#include <locale.h>
#include <netdb.h>
#include <nlist.h>
#include <paths.h>
@ -79,7 +81,6 @@ static const char rcsid[] =
#include <unistd.h>
#include <utmp.h>
#include <vis.h>
#include <locale.h>
#include <arpa/nameser.h>
#include <resolv.h>
@ -98,6 +99,7 @@ int header = 1; /* true if -h flag: don't print heading */
int nflag; /* true if -n flag: don't convert addrs */
int dflag; /* true if -d flag: output debug info */
int sortidle; /* sort by idle time */
int use_ampm; /* use AM/PM time */
char **sel_users; /* login array of particular users selected */
char domain[MAXHOSTNAMELEN];
@ -140,6 +142,7 @@ main(argc, argv)
char buf[MAXHOSTNAMELEN], errbuf[256];
(void)setlocale(LC_ALL, "");
use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
/* Are we w(1) or uptime(1)? */
if (this_is_uptime(argv[0]) == 0) {
@ -428,7 +431,8 @@ pr_header(nowp, nusers)
/*
* Print time of day.
*/
(void)strftime(buf, sizeof(buf) - 1, "%l:%M%p", localtime(nowp));
(void)strftime(buf, sizeof(buf) - 1,
use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp));
buf[sizeof(buf) - 1] = '\0';
(void)printf("%s ", buf);