FreeBSD/contrib/ntp/util/tg2.c
/* Calc day of year from year month & day */
/* Year - 0 means 2000, 100 means 2100. */
/* Month - 1 means January, 12 means December. */
/* DayOfMonth - 1 is first day of month */
Calc day of year from year month & day
Year - 0 means 2000, 100 means 2100.
Month - 1 means January, 12 means December.
DayOfMonth - 1 is first day of month
Calc day of year from year month & day Year - 0 means 2000 100 means 2100 . Month - 1 means January 12 means December . DayOfMonth - 1 is first day of month
int
ConvertMonthDayToDayOfYear (int YearValue, int MonthValue, int DayOfMonthValue)
	{
	int	ReturnValue;
	int	LeapYear;
	int	MonthCounter;
	int DaysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	LeapYear = FALSE;
	if  ((YearValue % 4) == 0)
		{
		if  ((YearValue % 100) == 0)
			{
			if  ((YearValue % 400) == 0)
				{
				LeapYear = TRUE;
				}
			}
		else
			{
			LeapYear = TRUE;
			}
		}
	if  (Debug)
		printf ("\nConvertMonthDayToDayOfYear(): Year %d %s a leap year.\n", YearValue+2000, LeapYear ? "is" : "is not");
	ReturnValue = DayOfMonthValue;
	for (MonthCounter=1; MonthCounter<MonthValue; MonthCounter++)
		{
		ReturnValue += DaysInMonth [ MonthCounter - 1 ];
		}
	if  ((LeapYear) && (MonthValue > 2))
		{
		ReturnValue++;
		}
	if  (Debug)
		printf ("\nConvertMonthDayToDayOfYear(): %4.4d-%2.2d-%2.2d represents day %3d of year.\n",
				YearValue+2000, MonthValue, DayOfMonthValue, ReturnValue);
	return (ReturnValue);
	}
int ConvertMonthDayToDayOfYear ( int YearValue , int MonthValue , int DayOfMonthValue ) { int ReturnValue ; int LeapYear ; int MonthCounter ; int DaysInMonth [ ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; LeapYear = FALSE ; if ( ( YearValue % 4 ) == 0 ) { if ( ( YearValue % 100 ) == 0 ) { if ( ( YearValue % 400 ) == 0 ) { LeapYear = TRUE ; } } else { LeapYear = TRUE ; } } if ( Debug ) printf ( " \n \n " , YearValue + 2000 , LeapYear ? " " : " " ) ; ReturnValue = DayOfMonthValue ; for ( MonthCounter = 1 ; MonthCounter < MonthValue ; MonthCounter ++ ) { ReturnValue += DaysInMonth [ MonthCounter - 1 ] ; } if ( ( LeapYear ) && ( MonthValue > 2 ) ) { ReturnValue ++ ; } if ( Debug ) printf ( " \n \n " , YearValue + 2000 , MonthValue , DayOfMonthValue , ReturnValue ) ; return ( ReturnValue ) ; }
Calc day of year from year month & day
Year - 0 means 2000, 100 means 2100.
Calc day of year from year month & day Year - 0 means 2000 100 means 2100 .
/* Array of days in a month.  Note that here January is zero. */ /* NB: have to add 1 to days in February in a leap year! */ /* Day of month given us starts in this algorithm. */ /* Add in days in month for each month past January. */ /* Add a day for leap years where we are past February. */