Repository navigation
fix(DataTypes/DATE): Adds support for DATE with Infinity/-Infinity - #8339
mkaufmaner wants to merge 6 commits into
Conversation
|
@mkaufmaner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @felixfbecker, @janmeier and @mickhansen to be potential reviewers. |
|
Marked as WIP because I am going to be working on the test coverage. |
| } | ||
| } else { // go ahread and parse as Date if required | ||
| if (!(value instanceof Date)) { | ||
| if (!(value instanceof Date) && value !== Infinity && value !== -Infinity) { |
There was a problem hiding this comment.
Too much logic here which should be handled by datatype and is postgres specific.
cc @janmeier Should we get dialect date type and call specific method to parse value ? This way postgres can do its thing and other dialect can do theirs ?
There was a problem hiding this comment.
Yep, a parse method on the date type could be a good idea
There was a problem hiding this comment.
Maybe custom getter and setter for the DATE.prototype?
|
I was looking into parse methods on the data type and will make changes accordingly. Thanks for the quick response! |
|
@janmeier @sushantdhiman After reviewing the code for For example, in order to support DATE.prototype.set = function set(value, key) {
if (!(value instanceof Date) && value !== Infinity && value !== -Infinity) {
value = new Date(value);
}
this.setDataValue(key, value);
}; |
|
Maybe we can go as far as abstracting the DATE.prototype.comparator = function comparator(value, originalValue) {
if (originalValue) {
if (!(originalValue instanceof Date) && value !== Infinity && value !== -Infinity) {
originalValue = new Date(originalValue);
}
if (value === originalValue || value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime()) {
return true;
}
}
};Thoughts? |
…etters, and comparators.
|
I see you are allowing users to set their own getter / setter for types, good idea but I think they should be able to call we should lock in an API about what we really want so we can improve other types and reduce code from model file as well. Please open an issue and we can discuss over there. First proposal could be to include a way in datatypes to set, get or compare. Let see what we can refactor |
janmeier
left a comment
There was a problem hiding this comment.
Looks like a good approach, it will be cleaner to move some if this code to datatypes
| this._virtualAttributes.push(name); | ||
| } else if (definition.type instanceof DataTypes.GEOMETRY) { | ||
| this._geometryAttributes.push(name); | ||
| if (definition.type) { |
There was a problem hiding this comment.
In which case would the definition not have a type?
| }).then(user => { | ||
| expect(user.username).to.equal('bob'); | ||
| expect(user.beforeTime).to.equal(-Infinity); | ||
| expect(user.sometime).to.not.equal(Infinity); |
|
@sushantdhiman I will work on a quick proposal with some examples as to what we should be aiming for when it comes to implementing a new API for data types. |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Adds support for Infinity/-Infinity with for DATE data types.
Closes #8336