Skip to content
Permalink
Browse files

vector file writer: fix saving of datetime values (fixes #14190)

  • Loading branch information
jef-n committed Feb 25, 2016
1 parent 9b5c683 commit a3f03f028a3a6be406ff21a17d988a41619e2439
Showing with 25 additions and 10 deletions.
  1. +25 −10 src/core/qgsvectorfilewriter.cpp
@@ -392,7 +392,7 @@ void QgsVectorFileWriter::init( QString vectorFileName, QString fileEncoding, co
if ( mOgrDriverName == "ESRI Shapefile" )
{
ogrType = OFTString;
ogrWidth = 12;
ogrWidth = 12; // %02d:%02d:%06.3f
}
else
{
@@ -401,7 +401,15 @@ void QgsVectorFileWriter::init( QString vectorFileName, QString fileEncoding, co
break;

case QVariant::DateTime:
ogrType = OFTDateTime;
if ( mOgrDriverName == "ESRI Shapefile" )
{
ogrType = OFTString;
ogrWidth = 24; // "%04d/%02d/%02d %02d:%02d:%06.3f"
}
else
{
ogrType = OFTDateTime;
}
break;

default:
@@ -1794,14 +1802,21 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
0, 0, 0, 0 );
break;
case QVariant::DateTime:
OGR_F_SetFieldDateTime( poFeature, ogrField,
attrValue.toDateTime().date().year(),
attrValue.toDateTime().date().month(),
attrValue.toDateTime().date().day(),
attrValue.toDateTime().time().hour(),
attrValue.toDateTime().time().minute(),
attrValue.toDateTime().time().second(),
0 );
if ( mOgrDriverName == "ESRI Shapefile" )
{
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toDateTime().toString( "yyyy/MM/dd hh:mm:ss.zzz" ) ).data() );
}
else
{
OGR_F_SetFieldDateTime( poFeature, ogrField,
attrValue.toDateTime().date().year(),
attrValue.toDateTime().date().month(),
attrValue.toDateTime().date().day(),
attrValue.toDateTime().time().hour(),
attrValue.toDateTime().time().minute(),
attrValue.toDateTime().time().second(),
0 );
}
break;
case QVariant::Time:
if ( mOgrDriverName == "ESRI Shapefile" )

1 comment on commit a3f03f0

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on a3f03f0 Feb 26, 2016

@jef-n , thanks.

Please sign in to comment.
You can’t perform that action at this time.