Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

standards/145082: Patch against w(1) & uptime(1) to use 24H time by default.

1 view
Skip to first unread message

jhell

unread,
Mar 27, 2010, 1:28:38 PM3/27/10
to freebsd-gn...@freebsd.org

>Number: 145082
>Category: standards
>Synopsis: Patch against w(1) & uptime(1) to use 24H time by default.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat Mar 27 17:30:02 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: jhell
>Release: FreeBSD 7.3-STABLE r205709
>Organization:
>Environment:
FreeBSD centel.dataix.local 7.3-STABLE FreeBSD 7.3-STABLE #0 r205709M Fri Mar 26 22:00:19 EDT 2010 ro...@centel.dataix.local:/usr/obj/usr/src/sys/SH4500 i386
>Description:
By default w(1) and uptime(1) use 12 hour time while the rest of the system uses 24 hour time. Example output above in uname -a and date(1) are two of the more commonly used commands that show 24 hour usage.

Programs with a default of 24 hour output:
last(1), date(1), who(1), ls(1)

Programs with a default of 12 hour output:
ps(1), w(1), uptime(1), others....
>How-To-Repeat:
Old output:

# date
Sat Mar 27 13:18:34 EDT 2010

# w
1:18PM up 26 days, 4:10, 1 users, load averages: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE WHAT
jhell p2 centel 1:13PM - w

# uptime
1:18PM up 26 days, 4:10, 1 users, load averages: 0.00, 0.00, 0.00
>Fix:
New output with attached patch:

# date
Sat Mar 27 13:18:34 EDT 2010

# w
13:18 up 4:23, 1 users, load averages: 0.15, 0.24, 0.18
USER TTY FROM LOGIN@ IDLE WHAT
jhell p2 :0.0 13:04 - w

# uptime
13:18 up 4:23, 1 users, load averages: 0.11, 0.19, 0.17


I recommend patching any other utilities to use 24 hour time by default since this can be modified at other levels if a user still wants 12 hour format.

Patch attached with submission follows:


extern.h | 2 +-
pr_time.c | 12 ++++++------
w.c | 6 +++---
3 files changed, 10 insertions(+), 10 deletions(-)

Index: usr.bin/w/pr_time.c
===================================================================
--- usr.bin/w/pr_time.c (revision 205709)
+++ usr.bin/w/pr_time.c (working copy)
@@ -75,23 +75,23 @@
tm.tm_year != tp.tm_year) {
/* The line below does not take DST into consideration */
/* else if (*now / 86400 != *started / 86400) { */
- fmt = use_ampm ? L"%a%I%p" : L"%a%H";
+ fmt = use_time24 ? L"%a%H" : L"%a%I%p";
}

- /* Default is hh:mm{am,pm}. */
+ /* Default is hh:mm. */
else {
- fmt = use_ampm ? L"%l:%M%p" : L"%k:%M";
+ fmt = use_time24 ? L"%H:%M" : L"%l:%M%p";
}

(void)wcsftime(buf, sizeof(buf), fmt, &tp);
len = wcslen(buf);
width = wcswidth(buf, len);
if (len == width)
- (void)wprintf(L"%-7.7ls", buf);
+ (void)wprintf(L" %-7.7ls", buf);
else if (width < 7)
- (void)wprintf(L"%ls%.*s", buf, 7 - width, " ");
+ (void)wprintf(L" %ls%.*s", buf, 7 - width, " ");
else {
- (void)wprintf(L"%ls", buf);
+ (void)wprintf(L" %ls", buf);
offset = width - 7;
}
return (offset);
Index: usr.bin/w/w.c
===================================================================
--- usr.bin/w/w.c (revision 205709)
+++ usr.bin/w/w.c (working copy)
@@ -100,7 +100,7 @@
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 */
+int use_time24; /* use 24 hour time */
int use_comma; /* use comma as floats separator */
char **sel_users; /* login array of particular users selected */

@@ -145,7 +145,7 @@
char *dot;

(void)setlocale(LC_ALL, "");
- use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
+ use_time24 = (*nl_langinfo(T_FMT) != '\0');
use_comma = (*nl_langinfo(RADIXCHAR) != ',');

/* Are we w(1) or uptime(1)? */
@@ -429,7 +429,7 @@
* Print time of day.
*/
if (strftime(buf, sizeof(buf),
- use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)) != 0)
+ use_time24 ? "%H:%M" : "%l:%M%p", localtime(nowp)) != 0)
(void)printf("%s ", buf);
/*
* Print how long system has been up.
Index: usr.bin/w/extern.h
===================================================================
--- usr.bin/w/extern.h (revision 205709)
+++ usr.bin/w/extern.h (working copy)
@@ -35,7 +35,7 @@
*/


-extern int use_ampm;
+extern int use_time24;

struct kinfo_proc;
int pr_attime(time_t *, time_t *);


>Release-Note:
>Audit-Trail:
>Unformatted:

jhell

unread,
Mar 27, 2010, 2:40:02 PM3/27/10
to freebsd-...@freebsd.org
The following reply was made to PR standards/145082; it has been noted by GNATS.

From: jhell <jh...@dataix.net>
To: jhell <jh...@DataIX.net>
Cc: freebsd-gn...@freebsd.org
Subject: Re: standards/145082: Patch against w(1) & uptime(1) to use 24H time
by default.

Date: Sat, 27 Mar 2010 14:15:12 -0400

PS: The one against ps(1) is much smaller ;)

Index: bin/ps/print.c
===================================================================
--- bin/ps/print.c (revision 205709)
+++ bin/ps/print.c (working copy)
@@ -414,7 +414,7 @@
VAR *v;
time_t then;
struct tm *tp;
- static int use_ampm = -1;
+ static int use_time24 = -1;
char buf[100];

v = ve->var;
@@ -422,16 +422,16 @@
(void)printf("%-*s", v->width, "-");
return;
}
- if (use_ampm < 0)


- use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');

+ if (use_time24 < 0)


+ use_time24 = (*nl_langinfo(T_FMT) != '\0');

then = k->ki_p->ki_start.tv_sec;
tp = localtime(&then);
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
(void)strftime(buf, sizeof(buf),
- use_ampm ? "%l:%M%p" : "%k:%M ", tp);
+ use_time24 ? "%H:%M" : "%l:%M%p ", tp);
} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
(void)strftime(buf, sizeof(buf),
- use_ampm ? "%a%I%p" : "%a%H ", tp);
+ use_time24 ? "%a%H" : "%a%I%p ", tp);
} else
(void)strftime(buf, sizeof(buf), "%e%b%y", tp);
(void)printf("%-*s", v->width, buf);

--

jhell

0 new messages