libtime++: Date and time calculation

◆ timeutil_norm()

void timeutil_norm ( timeutil_Ttime td)

Definition at line 187 of file timeutil.c.

References timeutil_date(), TIMEUTIL_FIRST_LINEAR, timeutil_is_leap(), timeutil_limits, and TIMEUTIL_N_ELEMENTS.

Referenced by timeutil_add(), and timeutil_finish().

189 {
190  int i;
191  long int carry, diy;
192  long int *ptr;
193 
194  ptr=(long int *)td;
195 
196  /* set correct values up to hours */
197  /* carry to doy values is worked out */
198  /* but doy value may still be incorrect */
199  for (i=TIMEUTIL_N_ELEMENTS-1; i>=TIMEUTIL_FIRST_LINEAR-1; i--) {
200  carry=(long int)(ptr[i]/timeutil_limits[i]);
201  if (ptr[i]<0) carry=carry-1;
202  ptr[i]=ptr[i]-carry*timeutil_limits[i];
203  ptr[i-1]=ptr[i-1]+carry;
204  }
205 
206  /* catch day carry for doy */
207  td->doy=td->doy+carry;
208 
209  /* work on doy and year */
210  if (td->year<70) td->year=td->year+2000;
211  if (td->year<100) td->year=td->year+1900;
212  if (td->doy>0) {
213  diy=365;
214  if (timeutil_is_leap(td->year)==1) diy=366;
215  while (td->doy>diy) {
216  td->doy=td->doy-diy;
217  td->year=td->year+1;
218  diy=365;
219  if (timeutil_is_leap(td->year)==1) diy=366;
220  }
221  } else {
222  while (td->doy<1) {
223  td->year=td->year-1;
224  diy=365;
225  if (timeutil_is_leap(td->year)==1) diy=366;
226  td->doy=td->doy+diy;
227  }
228  }
229  timeutil_date(td, td->doy);
230 } /* timeutil_norm */
long int doy
Definition: timeutil.h:58
static long int timeutil_limits[TIMEUTIL_N_ELEMENTS]
Definition: timeutil.c:56
void timeutil_date(timeutil_Ttime *td, long int doy)
Definition: timeutil.c:161
#define TIMEUTIL_N_ELEMENTS
Definition: timeutil.h:44
int timeutil_is_leap(long int year)
Definition: timeutil.c:137
#define TIMEUTIL_FIRST_LINEAR
Definition: timeutil.h:47
long int year
Definition: timeutil.h:58
Here is the call graph for this function:
Here is the caller graph for this function: