mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Return dates from the database without milliseconds (#9054)
no issue - we store dates without milliseconds in the database - our test environment does not use our model layer to insert data, this is related to https://github.com/TryGhost/Ghost/issues/7196 - so it can happen that the test env inserts unix timestamps instead of a formatted string - e.g. adding data via the model layer (e.g. via the API) the format is always normalised to `YYYY-MM-DD HH:mm:ss` - if we fetch the date from the database, we have a hook which sorts out knex returning different formats for dates - this hook wraps the returned date into a UTC moment date, but adds the current milliseconds on top - which can collide in tests when you have specific assertions - use `startOf` to ignore milliseconds - furthermore: remove the mentionings of `pg` (postgres)
This commit is contained in:
parent
b468d6dbe2
commit
3002747b68
1 changed files with 2 additions and 4 deletions
|
@ -172,12 +172,10 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
},
|
||||
|
||||
/**
|
||||
* all supported databases (pg, sqlite, mysql) return different values
|
||||
* all supported databases (sqlite, mysql) return different values
|
||||
*
|
||||
* sqlite:
|
||||
* - knex returns a UTC String
|
||||
* pg:
|
||||
* - has an active UTC session through knex and returns UTC Date
|
||||
* mysql:
|
||||
* - knex wraps the UTC value into a local JS Date
|
||||
*/
|
||||
|
@ -188,7 +186,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
if (value !== null
|
||||
&& schema.tables[self.tableName].hasOwnProperty(key)
|
||||
&& schema.tables[self.tableName][key].type === 'dateTime') {
|
||||
attrs[key] = moment(value).toDate();
|
||||
attrs[key] = moment(value).startOf('seconds').toDate();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue