Skip to content

Commit ad53309

Browse files
committed
GIBS-1098 Remove end range check and fixed issues with subdaily snapping
1 parent 1a18547 commit ad53309

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

src/mod_onearth/mod_onearth.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,10 @@ static void *r_file_pread(request_rec *r, char *fname,
318318
else {
319319
// check to see if there is a period
320320
if (sizeof(time_period) > 0) {
321-
apr_time_exp_t st = {0};
322-
apr_time_exp_t end = {0};
321+
apr_time_exp_t st; st.tm_year=0;st.tm_mon=0;st.tm_mday=1;st.tm_yday=1;st.tm_hour=0;st.tm_min=0;st.tm_sec=0;
323322
int interval = 0;
324323
int start_offset = 0;
325324
int start_leap = 0;
326-
int end_leap = 0;
327325
int i;
328326
for (i=0;i<num_periods;i++) {
329327
ap_log_error(APLOG_MARK,APLOG_WARNING,0,r->server,"Evaluating time period %s", time_period);
@@ -365,7 +363,7 @@ static void *r_file_pread(request_rec *r, char *fname,
365363
// get the offset from starting date
366364
start_offset = tm.tm_yday-st.tm_yday;
367365
// add prior years if not monthly
368-
if (time_period[(strlen(time_period)-1)] != 'M') {
366+
if (time_period[(strlen(time_period)-1)] != 'M' && hastime==0) {
369367
while (tm.tm_year>st.tm_year) {
370368
if ((st.tm_year%4)?0:((st.tm_year%400)?((st.tm_year%100)?1:0):1)==1) {
371369
start_offset+=366;
@@ -376,24 +374,15 @@ static void *r_file_pread(request_rec *r, char *fname,
376374
}
377375
}
378376

379-
time_period+=2; // Advance to date or time separator
380-
if (*time_period=='T') { // if hhmmss are included in time period
377+
// if hhmmss are included in time period
378+
if (strlen(time_period)>11) {
381379
time_period+=3;
382380
st.tm_hour = apr_atoi64(time_period);
383381
time_period+=3;
384382
st.tm_min = apr_atoi64(time_period);
385383
time_period+=3;
386384
st.tm_sec = apr_atoi64(time_period);
387385
}
388-
time_period+=1; // Advance to period end date
389-
390-
end.tm_year = apr_atoi64(time_period);
391-
time_period+=5;
392-
end.tm_mon = apr_atoi64(time_period);
393-
time_period+=3;
394-
end.tm_mday = apr_atoi64(time_period);
395-
end_leap=(end.tm_year%4)?0:((end.tm_year%400)?((end.tm_year%100)?1:0):1);
396-
end.tm_yday=end.tm_mday+moffset[end.tm_mon-1]+((end.tm_mon>2)?end_leap:0);
397386

398387
// ap_log_error(APLOG_MARK,APLOG_WARNING,0,r->server,"DEBUG Start time period: year %d month %d day %d hour %d minute %d second %d offset %d interval %d", st.tm_year, st.tm_mon, st.tm_mday, st.tm_hour, st.tm_min, st.tm_sec, start_offset, interval);
399388

@@ -410,12 +399,9 @@ static void *r_file_pread(request_rec *r, char *fname,
410399
span = request_day; // store old value
411400
request_day=tm.tm_mday+moffset[tm.tm_mon-interval]+((tm.tm_mon>2)?leap:0);
412401
span = span-request_day+1; // get actual span
413-
} else if (request_day <= end.tm_yday) {
402+
} else {
414403
// ap_log_error(APLOG_MARK,APLOG_WARNING,0,r->server,"%d [request day] - (%d [days since start] %% %d [period interval]) = %d [date]", request_day, start_offset, interval, (request_day-span));
415404
request_day = request_day - span;
416-
} else {
417-
time_period+=strlen(time_period)+1;
418-
continue;
419405
}
420406
}
421407
char old_char=*(fnloc+7);
@@ -426,21 +412,21 @@ static void *r_file_pread(request_rec *r, char *fname,
426412
int request_secs = (tm.tm_hour * 3600) + (tm.tm_min * 60) + tm.tm_sec;
427413
start_offset = ((tm.tm_yday * 86400) + request_secs) - ((start_offset * 86400) + (st.tm_hour * 3600) + (st.tm_min * 60) + st.tm_sec);
428414

429-
// calculate the last date in the span of the time interval
415+
// calculate the last time in the span of the time interval
430416
int span = start_offset % interval;
431417
// ap_log_error(APLOG_MARK,APLOG_WARNING,0,r->server,"%d [request seconds] - (%d [seconds since start] %% %d [period in seconds]) = %d [granule time in seconds]", request_secs, start_offset, interval, (request_secs-span));
432418
request_secs = request_secs - span;
433419

434420
// convert seconds to hhmmss
435-
tm.tm_hour = request_secs/3600;
421+
int tm_hour = request_secs/3600;
436422
request_secs = request_secs%3600;
437-
tm.tm_min = request_secs/60;
423+
int tm_min = request_secs/60;
438424
request_secs = request_secs%60;
439-
tm.tm_sec = request_secs;
425+
int tm_sec = request_secs;
440426

441427
char old_char=*(fnloc+13);
442-
// ap_log_error(APLOG_MARK,APLOG_WARNING,0,r->server,"period time is %04d-%02d-%02dT%02d:%02d:%02d", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
443-
sprintf(fnloc,"%04d%03d%02d%02d%02d",tm.tm_year,tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec);
428+
// ap_log_error(APLOG_MARK,APLOG_WARNING,0,r->server,"period time is %04d-%02d-%02dT%02d:%02d:%02d", tm.tm_year, tm.tm_mon, tm.tm_mday, tm_hour, tm_min, tm_sec);
429+
sprintf(fnloc,"%04d%03d%02d%02d%02d",tm.tm_year,tm.tm_yday, tm_hour, tm_min, tm_sec);
444430
*(fnloc+13)=old_char;
445431
}
446432

0 commit comments

Comments
 (0)