Skip to content

Commit

Permalink
Merge pull request #6 from PDOK/fix_datetime_backport
Browse files Browse the repository at this point in the history
Properly handle datetime fields
  • Loading branch information
copierrj authored Nov 12, 2021
2 parents 65b44bc + 291ea47 commit 8fbbd9c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion mapogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,38 @@ static char **msOGRGetValues(layerObj *layer, OGRFeatureH hFeature)

int *itemindexes = (int*)layer->iteminfo;

int nYear;
int nMonth;
int nDay;
int nHour;
int nMinute;
int nSecond;
int nTZFlag;

for(i=0; i<layer->numitems; i++) {
if (itemindexes[i] >= 0) {
// Extract regular attributes
values[i] = msStrdup(OGR_F_GetFieldAsString( hFeature, itemindexes[i]));
OGRFieldDefnH hFieldDefnRef = OGR_F_GetFieldDefnRef(hFeature, itemindexes[i]);
switch(OGR_Fld_GetType(hFieldDefnRef)) {
case OFTTime:
case OFTDate:
case OFTDateTime:
OGR_F_GetFieldAsDateTime(hFeature, itemindexes[i], &nYear, &nMonth, &nDay, &nHour, &nMinute, &nSecond, &nTZFlag);
switch(nTZFlag) {
case 0:
case 1:
values[i] = msStrdup(CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02d", nYear, nMonth, nDay, nHour, nMinute, nSecond));
break;
case 100:
values[i] = msStrdup(CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02dZ", nYear, nMonth, nDay, nHour, nMinute, nSecond));
break;
default:
values[i] = msStrdup(CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02d%+02d:00", nYear, nMonth, nDay, nHour, nMinute, nSecond, nTZFlag));
}
break;
default:
values[i] = msStrdup(OGR_F_GetFieldAsString(hFeature, itemindexes[i]));
}
} else if (itemindexes[i] == MSOGR_FID_INDEX ) {
values[i] = msStrdup(CPLSPrintf(CPL_FRMT_GIB,
(GIntBig) OGR_F_GetFID(hFeature)));
Expand Down

0 comments on commit 8fbbd9c

Please sign in to comment.