-
Notifications
You must be signed in to change notification settings - Fork 182
Adding support for fractional seconds #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,7 +412,7 @@ MySQL.prototype.fromColumnValue = function(prop, val) { | |
// MySQL allows, unless NO_ZERO_DATE is set, dummy date/time entries | ||
// new Date() will return Invalid Date for those, so we need to handle | ||
// those separate. | ||
if (!val || val == '0000-00-00 00:00:00' || val == '0000-00-00') { | ||
if (!val || /^0{4}(-00){2}( (00:){2}0{2}(\.0{1,6}){0,1}){0,1}$/.test(val)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what the end of the regex means
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex checks if val is one of the following values: 0000-00-00 You can see it working over here: https://regex101.com/r/IkM0wc/2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I get what the regex does. I am confused about the end part of the regex.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I get it! The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes much more sense now. |
||
val = null; | ||
} | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ describe('MySQL datetime handling', function() { | |
married: Boolean, | ||
dob: {type: 'DateString'}, | ||
createdAt: {type: Date, default: Date}, | ||
lastLogon: {type: Date, precision: 3, default: Date}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hi @joostdebruijn from the login on line#900, a property with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? I ran the tests again and Please note that the Loopback-type 'Date' maps on 'DATETIME' by default, see documentation and migration.js:725. The method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah I see, it's executed after |
||
}; | ||
|
||
// Modifying the connection timezones mid-flight is a pain, | ||
|
@@ -92,4 +93,22 @@ describe('MySQL datetime handling', function() { | |
}); | ||
} | ||
}); | ||
|
||
it('should allow use of fractional seconds', function(done) { | ||
var d = new Date('1971-06-22T12:34:56.789Z'); | ||
return Person.create({ | ||
name: 'Mr. Pink', | ||
gender: 'M', | ||
lastLogon: d, | ||
}).then(function(inst) { | ||
return Person.findById(inst.id); | ||
}).then(function(inst) { | ||
inst.should.not.eql(null); | ||
var lastLogon = new Date(inst.lastLogon); | ||
lastLogon.toJSON().should.eql(d.toJSON()); | ||
return done(); | ||
}).catch(function(err) { | ||
return done(err); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should we only add precision fractional second for timestamp values? According to MySQL documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I don't understand your comment. As the MySQL documentation said: TIME, DATETIME and TIMESTAMP types can have a precision. The DATE-type (of course) not.
This function checks the columntype and for columns with a type of time, datetime and timestamp and a precision is defined, the columnType will modified (see line 915), for example to DATETIME(3). This will allow to save values like 2017-05-07 12:34:56.789. When the column is of the type DATE, the function returns the colomnType without any modification.