From 291ea47763ae1c3226f5b088dfab007aab3096ee Mon Sep 17 00:00:00 2001 From: Reijer Copier Date: Thu, 11 Nov 2021 14:40:26 +0100 Subject: [PATCH] Properly handle datetime fields --- mapogr.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mapogr.cpp b/mapogr.cpp index 37c81f5bec..a7e9a22652 100644 --- a/mapogr.cpp +++ b/mapogr.cpp @@ -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; inumitems; 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)));