不要怂,就是干,撸起袖子干!

Commit 7029d2d6 by Bryan Sapot Committed by Sushant

Milliseconds in time stamps for createdAt, updatedAt for MySQL (#6442)

* fix(now): allow millisecons on createdAt and updatedAt

* test(timezone): timezone close check should allow 1 sec difference

* doc(changelog): add entry to change log

* test(now): create test for milliseconds in createdAt, updatedAt.

test(now): remove uneeded update code from test

removed unneeded file

* test(now): only run if mysql dialect

* test(lint): fix === lint error

* test(now): fix schema issue

* test(lint): remove space after comma
1 parent f8d0eabf
......@@ -9,6 +9,7 @@
- [FIXED] GroupedLimit when foreignKey has a field alias
- [FIXED] groupedLimit.through.where support
- [ADDED] `option.silent` for increment and decrement [#6795](https://github.com/sequelize/sequelize/pull/6795)
- [CHANGED] `now` function allow milliseconds in timestamps on mysql [#6441](https://github.com/sequelize/sequelize/issues/6441)
## BC breaks:
- `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
......
......@@ -422,7 +422,7 @@ exports.sliceArgs = sliceArgs;
function now(dialect) {
const now = new Date();
if (['postgres', 'sqlite'].indexOf(dialect) === -1) {
if (['mysql', 'postgres', 'sqlite'].indexOf(dialect) === -1) {
now.setMilliseconds(0);
}
return now;
......
......@@ -141,6 +141,37 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
if(dialect === 'mysql') {
it('should update timestamps w milliseconds', function() {
var User = this.sequelize.define('User' + config.rand(), {
name: DataTypes.STRING,
bio: DataTypes.TEXT,
email: DataTypes.STRING,
createdAt: {type: DataTypes.DATE(6), allowNull: false},
updatedAt: {type: DataTypes.DATE(6), allowNull: false}
}, {
timestamps: true
});
this.clock.tick(2100); //move the clock forward 2100 ms.
return User.sync({force: true}).then(function() {
return User.create({
name: 'snafu',
email: 'email'
}).then(function(user) {
return user.reload();
}).then(function(user) {
expect(user.get('name')).to.equal('snafu');
expect(user.get('email')).to.equal('email');
var testDate = new Date();
testDate.setTime(2100);
expect(user.get('createdAt')).to.equalTime(testDate);
});
});
});
}
it('should only save passed attributes', function () {
var user = this.User.build();
return user.save().then(function () {
......
......@@ -52,7 +52,7 @@ if (dialect !== 'sqlite') {
// Expect 7 hours difference, in milliseconds.
// This difference is expected since two instances, configured for each their timezone is trying to read the same timestamp
// this test does not apply to PG, since it stores the timezone along with the timestamp.
expect(this.normalUser.createdAt.getTime() - timezonedUser.createdAt.getTime()).to.be.closeTo(60 * 60 * 7 * 1000, 50);
expect(this.normalUser.createdAt.getTime() - timezonedUser.createdAt.getTime()).to.be.closeTo(60 * 60 * 7 * 1000, 1000);
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!