* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)pr_time.c 5.4 (Berkeley) %G%";
* Print the time since the user logged in.
* Note: SCCS forces the bizarre string manipulation, things like
* 5.4 get replaced in the source code.
/* If more than a week, use day-month-year. */
if (diff
> SECSPERDAY
* DAYSPERWEEK
)
(void)strcpy(fmt
, "%d%b%y");
/* If not today, use day-hour-am/pm. */
else if (*now
/ SECSPERDAY
!= *started
/ SECSPERDAY
) {
(void)strcpy(fmt
, "%a%%%p");
/* Default is hh:mm{am,pm}. */
(void)strcpy(fmt
, "%l:%%%p");
(void)strftime(buf
, sizeof(buf
), fmt
, tp
);
/* If idle more than 36 hours, print as a number of days. */
if (idle
>= 36 * SECSPERHOUR
)
(void)printf(" %ddays ", idle
/ SECSPERDAY
);
/* If idle more than an hour, print as HH:MM. */
else if (idle
>= SECSPERHOUR
)
(void)printf(" %2d:%02d ",
idle
/ SECSPERHOUR
, (idle
% SECSPERHOUR
) / SECSPERMIN
);
/* Else print the minutes idle. */
(void)printf(" %2d ", idle
/ SECSPERMIN
);