FreeBSD/usr.bin/w/pr_time.c
/*
 * pr_attime --
 *	Print the time since the user logged in.
 */
pr_attime
Print the time since the user logged in.
pr_attime Print the time since the user logged in .
int
pr_attime(time_t *started, time_t *now)
{
	static wchar_t buf[256];
	struct tm tp, tm;
	time_t diff;
	const wchar_t *fmt;
	int len, width, offset = 0;
	tp = *localtime(started);
	tm = *localtime(now);
	diff = *now - *started;
	if (diff > 86400 * 7)
		fmt = L"%d%b%y";
	else if (tm.tm_mday != tp.tm_mday ||
		 tm.tm_mon != tp.tm_mon ||
		 tm.tm_year != tp.tm_year) {
		fmt = use_ampm ? L"%a%I%p" : L"%a%H";
	}
	else {
		fmt = use_ampm ? L"%l:%M%p" : L"%k:%M";
	}
	(void)wcsftime(buf, sizeof(buf), fmt, &tp);
	len = wcslen(buf);
	width = wcswidth(buf, len);
	xo_attr("since", "%lu", (unsigned long) *started);
	xo_attr("delta", "%lu", (unsigned long) diff);
	if (len == width)
		xo_emit("{:login-time/%-7.7ls/%ls}", buf);
	else if (width < 7)
	        xo_emit("{:login-time/%ls}%.*s", buf, 7 - width, "      ");
	else {
		xo_emit("{:login-time/%ls}", buf);
		offset = width - 7;
	}
	return (offset);
}
int pr_attime ( time_t * started , time_t * now ) { static wchar_t buf [ 256 ] ; struct tm tp , tm ; time_t diff ; const wchar_t * fmt ; int len , width , offset = 0 ; tp = * localtime ( started ) ; tm = * localtime ( now ) ; diff = * now - * started ; if ( diff > 86400 * 7 ) fmt = L" " ; else if ( tm . tm_mday != tp . tm_mday || tm . tm_mon != tp . tm_mon || tm . tm_year != tp . tm_year ) { fmt = use_ampm ? L" " : L" " ; } else { fmt = use_ampm ? L" " : L" " ; } ( void ) wcsftime ( buf , sizeof ( buf ) , fmt , & tp ) ; len = wcslen ( buf ) ; width = wcswidth ( buf , len ) ; xo_attr ( " " , " " , ( unsigned long ) * started ) ; xo_attr ( " " , " " , ( unsigned long ) diff ) ; if ( len == width ) xo_emit ( " " , buf ) ; else if ( width < 7 ) xo_emit ( " " , buf , 7 - width , " " ) ; else { xo_emit ( " " , buf ) ; offset = width - 7 ; } return ( offset ) ; }
pr_attime
      Print the time since the user logged in.
pr_attime Print the time since the user logged in .
/* If more than a week, use day-month-year. */ /* If not today, use day-hour-am/pm. */ /* The line below does not take DST into consideration */ /* else if (*now / 86400 != *started / 86400) { */ /* Default is hh:mm{am,pm}. */