Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll) git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
110 lines
2.0 KiB
C
Executable File
110 lines
2.0 KiB
C
Executable File
/* void AddDaysToDate365NoLeapYear( m2, d2, y2, m1, d1, y1, ndays )
|
|
*
|
|
* ARGUMENTS
|
|
* int m1, d1, y1 - Specify a base date.
|
|
* int *m2, *d2, *y2 - Specify a date to be calculated
|
|
* int ndays - Number of days (+ or -) to be added to base
|
|
*
|
|
* DESCRIPTION
|
|
* A signed number of days (ndays) is added to the base date to form a
|
|
* second date which is transferred to the variables m2,d2,y2. If any of
|
|
* the arguments are NULL on input, an error results.
|
|
*
|
|
* Years < 100 are taken to be in 20th century.
|
|
*
|
|
* Years are considered to have 365 days. Leap years are considered here.
|
|
*
|
|
* SIDE EFFECTS
|
|
* Modified d2, m2, y2.
|
|
*
|
|
* RETURNS
|
|
* None.
|
|
*
|
|
* POSSIBLE ERROR CODES
|
|
*
|
|
* GM_ARGVAL
|
|
* GM_NULLPOINTER
|
|
*
|
|
* AUTHOR
|
|
* Don Killen 03-Feb-1988 16:27:32
|
|
* Copyright (C) 1988-1990 Greenleaf Software Inc. All rights reserved.
|
|
*
|
|
* MODIFICATIONS
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "gm.h"
|
|
#include "gmsystem.h"
|
|
|
|
void AddDaysToDate365NoLeapYear(m2,d2,y2,m1,d1,y1,ndays)
|
|
int m1,*m2,d1,*d2,y1,*y2,ndays;
|
|
{
|
|
long n1;
|
|
int np, x, mt, dt=1, dp, ny;
|
|
|
|
_MacStart(GM_ADATENLY);
|
|
|
|
if (d2==NULL||m2==NULL||y2==NULL) {
|
|
_MacErr(GM_NULLPOINTER);
|
|
_MacRetV;
|
|
}
|
|
|
|
if ( m1<1 || m1>12 || d1<1 || d1>31 || y1<1 || y1>9999 ) {
|
|
_MacErr(GM_ARGVAL);
|
|
_MacRetV;
|
|
}
|
|
|
|
if (m1<=2) {
|
|
x=0;
|
|
}
|
|
else {
|
|
x=(4*m1 + 23) / 10;
|
|
}
|
|
|
|
/* compute day # */
|
|
n1 = (long) y1 * 365L + (long) (31*(m1-1) + d1 - x)
|
|
+(long) ndays;
|
|
|
|
/* estimate year */
|
|
*y2 = (int) (n1 / 365L);
|
|
np = (int) (n1 - (long) (*y2) * 365L);
|
|
/* correct year estimate */
|
|
while (np<1) { /* year too large */
|
|
*y2 = (*y2)-1;
|
|
np = np + 365;
|
|
}
|
|
|
|
ny = 365;
|
|
while (np > ny) { /* year too small */
|
|
*y2 = (*y2)+1;
|
|
np = np-365;
|
|
}
|
|
|
|
/* handle Jan. & Feb. */
|
|
if (np <= 31) {
|
|
*m2 = 1;
|
|
*d2 = np;
|
|
_MacRetV;
|
|
}
|
|
|
|
if (np <= 59) {
|
|
*m2 = 2;
|
|
*d2 = np - 31;
|
|
_MacRetV;
|
|
}
|
|
|
|
/* handle other months */
|
|
mt = 2;
|
|
do {
|
|
mt++;
|
|
dp = dt;
|
|
dt = np - 31 * (mt - 1) + (4 * mt + 23) / 10;
|
|
} while (dt>=1);
|
|
*m2 = mt-1;
|
|
*d2 = dp;
|
|
|
|
_MacRetV;
|
|
}
|