* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)convtime.c 5.3 (Berkeley) 6/30/88";
** CONVTIME -- convert time
** Takes a time as an ascii string with a trailing character
** For example, "3d12h" is three and a half days.
** p -- pointer to ascii time.
while (isdigit(c
= *p
++))
** PINTVL -- produce printable version of a time interval
** intvl -- the interval to be converted
** brief -- if TRUE, print this in an extremely compact form
** (basically used for logging).
** A pointer to a string version of intvl suitable for
** The string returned is in a static buffer.
# define PLURAL(n) ((n) == 1 ? "" : "s")
if (intvl
== 0 && !brief
)
/* decode the interval into weeks, days, hours, minutes, seconds */
/* now turn it into a sexy form */
(void) sprintf(p
, "%d+", dy
);
(void) sprintf(p
, "%02d:%02d:%02d", hr
, mi
, se
);
/* use the verbose form */
(void) sprintf(p
, ", %d week%s", wk
, PLURAL(wk
));
(void) sprintf(p
, ", %d day%s", dy
, PLURAL(dy
));
(void) sprintf(p
, ", %d hour%s", hr
, PLURAL(hr
));
(void) sprintf(p
, ", %d minute%s", mi
, PLURAL(mi
));
(void) sprintf(p
, ", %d second%s", se
, PLURAL(se
));