//  Beta release only.
//
//  Copyright(c) Ivyware Pty Ltd 2006  (all rights reserved)
//               MELBOURNE, VICTORIA, AUSTRALIA, 3130
//
//  Provided no fee is charged (either by the distributer or user)
//  permission to use, copy, modify, and distribute this software and
//  its documentation for any purpose and without fee is hereby granted,
//  provided that the above copyright notice appear in all copies and
//  that both that copyright notice and this permission notice appear
//  in supporting documentation.
//
//  No waranty or suitablity for purpose is implied.
//
//
//  Implementation for CTime extensions
//
#include "StdAfx.h"
#include "Sys/timeb.h"

#include "CTime_Ext.h"

//
//  Days in month calculation
//
//  Parameters:  int nYear
//
//               int nMonth
//
//  Returns:     int
//               Number of days in month
int
DaysInMonth ( int nYear, int nMonth )
{
    // Introduce locals
    const short nDaysInMonth[12] = { 31, 28, 31, 30, 31, 30
                                   , 31, 31, 30, 31, 30, 31 };

    // To be sure to be sure
    if ( nMonth <  1 ||
         nMonth > 12    )
      return 0;

    // Anything but February
    if ( nMonth != 2 )
      return nDaysInMonth[nMonth-1];

    // Leap years
    if ( nYear%4 != 0 )
      return 28;
    else if ( nYear%100 == 0 )
      return 28;
    return 29;
}
