1 /*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 04/04/94";
10 #endif /* not lint */
11
12 #include <sys/types.h>
13 #include <sys/time.h>
14
15 #include <stdio.h>
16 #include <string.h>
17 #include <tzfile.h>
18
19 #include "extern.h"
20
21 /*
22 * pr_attime --
23 * Print the time since the user logged in.
24 *
25 * Note: SCCS forces the bizarre string manipulation, things like
26 * 8.2 get replaced in the source code.
27 */
28 void
pr_attime(started,now)29 pr_attime(started, now)
30 time_t *started, *now;
31 {
32 static char buf[256];
33 struct tm *tp;
34 time_t diff;
35 char fmt[20];
36
37 tp = localtime(started);
38 diff = *now - *started;
39
40 /* If more than a week, use day-month-year. */
41 if (diff > SECSPERDAY * DAYSPERWEEK)
42 (void)strcpy(fmt, "%d%b%y");
43
44 /* If not today, use day-hour-am/pm. */
45 else if (*now / SECSPERDAY != *started / SECSPERDAY) {
46 (void)strcpy(fmt, __CONCAT("%a%", "I%p"));
47 }
48
49 /* Default is hh:mm{am,pm}. */
50 else {
51 (void)strcpy(fmt, __CONCAT("%l:%", "M%p"));
52 }
53
54 (void)strftime(buf, sizeof(buf), fmt, tp);
55 (void)printf("%s", buf);
56 }
57
58 /*
59 * pr_idle --
60 * Display the idle time.
61 */
62 void
pr_idle(idle)63 pr_idle(idle)
64 time_t idle;
65 {
66 /* If idle more than 36 hours, print as a number of days. */
67 if (idle >= 36 * SECSPERHOUR)
68 (void)printf(" %ddays ", idle / SECSPERDAY);
69
70 /* If idle more than an hour, print as HH:MM. */
71 else if (idle >= SECSPERHOUR)
72 (void)printf(" %2d:%02d ",
73 idle / SECSPERHOUR, (idle % SECSPERHOUR) / SECSPERMIN);
74
75 /* Else print the minutes idle. */
76 else
77 (void)printf(" %2d ", idle / SECSPERMIN);
78 }
79