lib/libc/stdtime/strftime.c
static char *
_yconv(const int a, const int b, const int convert_top, const int convert_yy,
       char *pt, const char * const ptlim)
{
	int	lead;
	int	trail;

#define DIVISOR	100
	trail = a % DIVISOR + b % DIVISOR;
	lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
	trail %= DIVISOR;
	if (trail < 0 && lead > 0) {
		trail += DIVISOR;
		--lead;
	} else if (lead < 0 && trail > 0) {
		trail -= DIVISOR;
		++lead;
	}
	if (convert_top) {
		if (lead == 0 && trail < 0)
			pt = _add("-0", pt, ptlim);
		else	pt = _conv(lead, "%02d", pt, ptlim);
	}
	if (convert_yy)
		pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
	return pt;
}
/*
** POSIX and the C Standard are unclear or inconsistent about
** what %C and %y do if the year is negative or exceeds 9999.
** Use the convention that %C concatenated with %y yields the
** same output as %Y, and that %Y contains at least 4 bytes,
** with more only if necessary.
*/
POSIX and the C Standard are unclear or inconsistent about
what %C and %y do if the year is negative or exceeds 9999.
Use the convention that %C concatenated with %y yields the
same output as %Y, and that %Y contains at least 4 bytes,
with more only if necessary.
POSIX and the C Standard are unclear or inconsistent about what %C and %y do if the year is negative or exceeds 9999 . Use the convention that %C concatenated with %y yields the same output as %Y and that %Y contains at least 4 bytes with more only if necessary .
static char *
_yconv(const int a, const int b, const int convert_top, const int convert_yy,
       char *pt, const char * const ptlim)
{
	int	lead;
	int	trail;
#define DIVISOR	100
	trail = a % DIVISOR + b % DIVISOR;
	lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
	trail %= DIVISOR;
	if (trail < 0 && lead > 0) {
		trail += DIVISOR;
		--lead;
	} else if (lead < 0 && trail > 0) {
		trail -= DIVISOR;
		++lead;
	}
	if (convert_top) {
		if (lead == 0 && trail < 0)
			pt = _add("-0", pt, ptlim);
		else	pt = _conv(lead, "%02d", pt, ptlim);
	}
	if (convert_yy)
		pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
	return pt;
}
static char * _yconv ( const int a , const int b , const int convert_top , const int convert_yy , char * pt , const char * const ptlim ) { int lead ; int trail ; #define DIVISOR 	100 trail = a % DIVISOR + b % DIVISOR ; lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR ; trail %= DIVISOR ; if ( trail < 0 && lead > 0 ) { trail += DIVISOR ; -- lead ; } else if ( lead < 0 && trail > 0 ) { trail -= DIVISOR ; ++ lead ; } if ( convert_top ) { if ( lead == 0 && trail < 0 ) pt = _add ( " " , pt , ptlim ) ; else pt = _conv ( lead , " " , pt , ptlim ) ; } if ( convert_yy ) pt = _conv ( ( ( trail < 0 ) ? - trail : trail ) , " " , pt , ptlim ) ; return pt ; }
POSIX and the C Standard are unclear or inconsistent about
what %C and %y do if the year is negative or exceeds 9999.
POSIX and the C Standard are unclear or inconsistent about what %C and %y do if the year is negative or exceeds 9999 .