mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Stripped moment from data-manipulation.fixDatesWhenFetch
- we don't need moment here and we can produce the same result in JS Date, which is a lot faster than moment
This commit is contained in:
parent
7bd70a3ab2
commit
96f6adecac
1 changed files with 9 additions and 4 deletions
|
@ -54,14 +54,19 @@ module.exports = function (Bookshelf) {
|
|||
|
||||
Object.keys(attrs).forEach((key) => {
|
||||
if (attrs[key] && tableDef?.[key]?.type === 'dateTime') {
|
||||
const dateMoment = moment(attrs[key]);
|
||||
const dateValue = new Date(attrs[key]);
|
||||
|
||||
// CASE: You are somehow able to store e.g. 0000-00-00 00:00:00
|
||||
// Protect the code base and return the current date time.
|
||||
if (dateMoment.isValid()) {
|
||||
attrs[key] = dateMoment.startOf('seconds').toDate();
|
||||
if (!isNaN(dateValue.getTime())) {
|
||||
// Valid date: set to the start of the second
|
||||
dateValue.setMilliseconds(0);
|
||||
attrs[key] = dateValue;
|
||||
} else {
|
||||
attrs[key] = moment().startOf('seconds').toDate();
|
||||
// Invalid date: use current date-time
|
||||
const currentDate = new Date();
|
||||
currentDate.setMilliseconds(0);
|
||||
attrs[key] = currentDate;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue