home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* *** newdate.c *** */
- /* */
- /* This function returns a new julian date, expressed as an unsigned */
- /* long integer, arrived at by adding a specified number of days of a */
- /* specified type to the starting julian date input. */
- /* */
- /* In short, it adds days to a date to get a new date. */
- /* */
- /* The input values to the function, in their proper order, are: */
- /* */
- /* 1. the beginning julian date ( unsigned long ) */
- /* */
- /* 2. the number of days to be added ( signed long ) */
- /* */
- /* 3. the numerical code representing the type */
- /* of days to be added ( described below ) ( unsigned int ) */
- /* */
- /* The following is a list of the codes used to define the */
- /* type of days that are to be added to the start date: */
- /* */
- /* CODE - EXPLANATION - */
- /* */
- /* 0 - weekdays and weekends (all days) */
- /* */
- /* 1 - weekdays and Saturdays only (Sundays skipped over) */
- /* */
- /* 2 - weekdays only (weekends skipped over) */
- /* */
- /* NOTE - input of any code not listed above will be */
- /* interpreted as code 0. */
- /* */
- /************************************************************************/
-
- extern int dow( unsigned long );
-
- long newdate( juldte, days, incl )
-
- long juldte, days;
- unsigned int incl;
-
- {
- int eff = 7 - ( incl = incl > 2 ? 0 : incl ), rvrse = 0;
-
- if ( !incl-- ) return( juldte + days );
-
- if ( days < 0 )
- {
- rvrse = eff + 1;
- juldte += !dow( juldte ) + 2 * ( incl && !( 6 - dow( juldte ) ) );
- }
- else juldte -= !dow( juldte ) + ( incl && !( dow( juldte ) % 6 ) );
-
- return( juldte + days / eff * 7 + days % eff + ++incl *
- ( ( dow( juldte ) + days % eff - rvrse ) / ( eff + 1 ) ) );
- }