Skip to content

Commit

Permalink
introduced function to check if a given date lies in the future
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Katerndahl <florian@katerndahl.com>
  • Loading branch information
Florian-Katerndahl committed Aug 2, 2021
1 parent c777926 commit f86c985
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cross-level/datesys-cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,13 @@ struct tm *timeinfo;
return;
}

int date_overshoot(date_t *d){
date_t today;
current_date(&today);

if (d->doy > today.doy && d->year > today.year) {
return 1;
} else {
return 0;
}
}
1 change: 1 addition & 0 deletions src/cross-level/datesys-cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern "C" {
void current_date(date_t *d);
void date_plus(date_t *d);
void date_minus(date_t *d);
int date_overshoot(date_t *d);

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions src/lower-level/_lut-modis.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ int opt;
strncpy(cm, optarg+13, 2); cm[2] = '\0';
strncpy(cd, optarg+15, 2); cd[2] = '\0';
set_date(&args->date_end, atoi(cy), atoi(cm), atoi(cd));
if (date_overshoot(&args->date_start) || date_overshoot(&args->date_end)) {
fprintf(stderr, "start or end date exceed current date\n");
usage(argv[0], FAILURE);
}
break;
case 't':
if (strcmp(optarg, "true") == 0){
Expand Down

0 comments on commit f86c985

Please sign in to comment.