mirror of https://github.com/ecmwf/eccodes.git
Do not use strptime. Use existing date conversion function. Tests now pass
This commit is contained in:
parent
c2763516d4
commit
2f72fdec8a
|
@ -151,7 +151,8 @@ static int get_native_type(grib_accessor* a)
|
|||
return GRIB_TYPE_LONG;
|
||||
}
|
||||
|
||||
static int select_datetime(grib_accessor* a) {
|
||||
static int select_datetime(grib_accessor* a)
|
||||
{
|
||||
int ret=0;
|
||||
long compressed=0;
|
||||
grib_accessor_bufr_extract_datetime_subsets *self =(grib_accessor_bufr_extract_datetime_subsets*)a;
|
||||
|
@ -163,11 +164,8 @@ static int select_datetime(grib_accessor* a) {
|
|||
|
||||
if (compressed) {
|
||||
size_t n;
|
||||
struct tm start;
|
||||
struct tm end;
|
||||
struct tm datetime;
|
||||
time_t start_t,end_t,datetime_t;
|
||||
char start_str[80]={0,},end_str[80]={0,},datetime_str[80]={0,};
|
||||
double julianStart=0, julianEnd=0, julianDT=0;
|
||||
char start_str[80]={0,},end_str[80]={0,};
|
||||
long yearRank,monthRank,dayRank,hourRank,minuteRank,secondRank;
|
||||
long yearStart,monthStart,dayStart,hourStart,minuteStart,secondStart;
|
||||
long yearEnd,monthEnd,dayEnd,hourEnd,minuteEnd,secondEnd;
|
||||
|
@ -297,9 +295,8 @@ static int select_datetime(grib_accessor* a) {
|
|||
ret=grib_get_long(h,"extractDateTimeSecondStart",&secondStart);
|
||||
if (ret) secondStart=0;
|
||||
sprintf(start_str,"%04ld/%02ld/%02ld %02ld:%02ld:%02ld",yearStart,monthStart,dayStart,hourStart,minuteStart,secondStart);
|
||||
strptime(start_str, "%Y/%m/%d %T", &start);
|
||||
start_t=mktime(&start);
|
||||
if (start_t==-1) return GRIB_INTERNAL_ERROR;
|
||||
grib_datetime_to_julian(yearStart,monthStart,dayStart,hourStart,minuteStart,secondStart, &julianStart);
|
||||
/* TODO: if error occurred return GRIB_INTERNAL_ERROR */
|
||||
|
||||
ret=grib_get_long(h,"extractDateTimeYearEnd",&yearEnd);
|
||||
if (ret) return ret;
|
||||
|
@ -314,22 +311,20 @@ static int select_datetime(grib_accessor* a) {
|
|||
ret=grib_get_long(h,"extractDateTimeSecondEnd",&secondEnd);
|
||||
if (ret) secondEnd=0;
|
||||
sprintf(end_str,"%04ld/%02ld/%02ld %02ld:%02ld:%02ld",yearEnd,monthEnd,dayEnd,hourEnd,minuteEnd,secondEnd);
|
||||
strptime(end_str, "%Y/%m/%d %T", &end);
|
||||
end_t=mktime(&end);
|
||||
if (end_t==-1) return GRIB_INTERNAL_ERROR;
|
||||
if (difftime(end_t,start_t)<=0) {
|
||||
grib_datetime_to_julian(yearEnd,monthEnd,dayEnd,hourEnd,minuteEnd,secondEnd, &julianEnd);
|
||||
/* TODO: if error occurred return GRIB_INTERNAL_ERROR */
|
||||
|
||||
if (julianEnd <= julianStart) {
|
||||
grib_context_log(c,GRIB_LOG_ERROR,"Wrong definition of time interval: end (%s) is not after start (%s)",end_str,start_str);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
for (i=0;i<numberOfSubsets;i++) {
|
||||
sprintf(datetime_str,"%04ld/%02ld/%02ld %02ld:%02ld:%02ld",year[i],month[i],day[i],hour[i],minute[i],(long)round(second[i]));
|
||||
strptime(datetime_str, "%Y/%m/%d %T", &datetime);
|
||||
datetime_t=mktime(&datetime);
|
||||
if (datetime_t==-1) return GRIB_INTERNAL_ERROR;
|
||||
/* printf("++++++ %s <= %s (%g) <= %s\n",start_str,datetime_str,second[i],end_str); */
|
||||
/*sprintf(datetime_str,"%04ld/%02ld/%02ld %02ld:%02ld:%02ld",year[i],month[i],day[i],hour[i],minute[i],(long)round(second[i]));*/
|
||||
grib_datetime_to_julian(year[i],month[i],day[i],hour[i],minute[i],(long)round(second[i]), &julianDT);
|
||||
/* TODO: if error occurred return GRIB_INTERNAL_ERROR */
|
||||
|
||||
if (difftime(datetime_t,start_t)>=0 && difftime(end_t,datetime_t)>=0) {
|
||||
if (julianDT>=julianStart && julianEnd>=julianDT) {
|
||||
grib_iarray_push(subsets,i+1);
|
||||
/* printf("++++++++ %ld\n",i+1); */
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ extern "C" {
|
|||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Microsoft Windows Visual Studio support */
|
||||
#include "eccodes_windef.h"
|
||||
|
|
|
@ -52,7 +52,7 @@ list( APPEND tests2
|
|||
bufr_count
|
||||
bufr_get
|
||||
bufr_filter
|
||||
#bufr_filter_extract_datetime
|
||||
bufr_filter_extract_datetime
|
||||
bufr_filter_extract_area
|
||||
bufr_json
|
||||
bufr_ls
|
||||
|
|
Loading…
Reference in New Issue