Skip to content

Commit

Permalink
only converting strings to dates if they parse as dates
Browse files Browse the repository at this point in the history
  • Loading branch information
chelm committed Jun 24, 2015
1 parent a7f0a7d commit fc1664f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/FeatureServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
type = (( idField && key === idField ) ? 'esriFieldTypeOID' : (self.fieldType( props[ key ])||'esriFieldTypeString') );

// check for a date; set type
if ( new Date(props[ key ]) !== "Invalid Date" && !isNaN(new Date(props[ key ])) ) {
if ( typeof props[ key ] === 'string' && (new Date(props[ key ]) !== "Invalid Date" && !isNaN(new Date(props[ key ])) )) {
type = 'esriFieldTypeDate';
}

Expand Down
6 changes: 4 additions & 2 deletions test/models/featureservice-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('FeatureServices Model', function(){
var input = {
propInt: 10,
propFloat:10.1,
propString:'Awesome'
propString:'Awesome',
propDate: 'Wed Jun 24 2015 08:18:24'
};
var fieldObj = fs.fields( input ),
fields = fieldObj.fields;
Expand All @@ -57,10 +58,11 @@ describe('FeatureServices Model', function(){
f.should.have.property('type');
f.should.have.property('name');
f.should.have.property('alias');
});
})
fields[0].type.should.equal('esriFieldTypeInteger');
fields[1].type.should.equal('esriFieldTypeDouble');
fields[2].type.should.equal('esriFieldTypeString');
fields[3].type.should.equal('esriFieldTypeDate');
done();
});
});
Expand Down

0 comments on commit fc1664f

Please sign in to comment.