Skip to content

Commit

Permalink
vector file writer: fix saving of datetime values (fixes #14190)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 25, 2016
1 parent 9b5c683 commit a3f03f0
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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
{
Expand All @@ -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:
Expand Down Expand Up @@ -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" )
Expand Down

1 comment on commit a3f03f0

@nirvn
Copy link
Contributor

@nirvn nirvn commented on a3f03f0 Feb 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jef-n , thanks.

Please sign in to comment.