mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Reverted "Stripped moment from data-manipulation.fixDatesWhenFetch
"
refs https://ghost.slack.com/archives/C02G9E68C/p1729083762579479
- this reverts commit 96f6adecac
.
This commit is contained in:
parent
7da234643e
commit
1068f6ed13
1 changed files with 4 additions and 9 deletions
|
@ -54,19 +54,14 @@ module.exports = function (Bookshelf) {
|
||||||
|
|
||||||
Object.keys(attrs).forEach((key) => {
|
Object.keys(attrs).forEach((key) => {
|
||||||
if (attrs[key] && tableDef?.[key]?.type === 'dateTime') {
|
if (attrs[key] && tableDef?.[key]?.type === 'dateTime') {
|
||||||
const dateValue = new Date(attrs[key]);
|
const dateMoment = moment(attrs[key]);
|
||||||
|
|
||||||
// CASE: You are somehow able to store e.g. 0000-00-00 00:00:00
|
// 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.
|
// Protect the code base and return the current date time.
|
||||||
if (!isNaN(dateValue.getTime())) {
|
if (dateMoment.isValid()) {
|
||||||
// Valid date: set to the start of the second
|
attrs[key] = dateMoment.startOf('seconds').toDate();
|
||||||
dateValue.setMilliseconds(0);
|
|
||||||
attrs[key] = dateValue;
|
|
||||||
} else {
|
} else {
|
||||||
// Invalid date: use current date-time
|
attrs[key] = moment().startOf('seconds').toDate();
|
||||||
const currentDate = new Date();
|
|
||||||
currentDate.setMilliseconds(0);
|
|
||||||
attrs[key] = currentDate;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue