Fix date field to amend to timezone offset
This commit is contained in:
@@ -6,6 +6,14 @@ const Events: CollectionConfig = {
|
|||||||
useAsTitle: 'name'
|
useAsTitle: 'name'
|
||||||
},
|
},
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
|
hooks: {
|
||||||
|
afterRead: [
|
||||||
|
({ doc }) => {
|
||||||
|
delete doc.UTCOffset;
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
@@ -37,6 +45,17 @@ const Events: CollectionConfig = {
|
|||||||
timeFormat: 'HH:mm',
|
timeFormat: 'HH:mm',
|
||||||
timeIntervals: 15
|
timeIntervals: 15
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
hooks: {
|
||||||
|
beforeValidate: [ ({ value, siblingData }) => {
|
||||||
|
const d = new Date(value);
|
||||||
|
|
||||||
|
const hourOffset = parseInt(siblingData.UTCOffset) / -60;
|
||||||
|
|
||||||
|
d.setHours(d.getHours() + hourOffset);
|
||||||
|
|
||||||
|
return d;
|
||||||
|
} ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -62,10 +81,30 @@ const Events: CollectionConfig = {
|
|||||||
timeFormat: 'HH:mm',
|
timeFormat: 'HH:mm',
|
||||||
timeIntervals: 15
|
timeIntervals: 15
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
hooks: {
|
||||||
|
beforeValidate: [ ({ value, siblingData }) => {
|
||||||
|
const d = new Date(value);
|
||||||
|
|
||||||
|
const hourOffset = parseInt(siblingData.UTCOffset) / -60;
|
||||||
|
|
||||||
|
d.setHours(d.getHours() + hourOffset);
|
||||||
|
|
||||||
|
return d;
|
||||||
|
} ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: 'UTCOffset',
|
||||||
|
type: 'text',
|
||||||
|
defaultValue: () => new Date().getTimezoneOffset(),
|
||||||
|
admin: {
|
||||||
|
position: 'sidebar',
|
||||||
|
readOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,4 +41,5 @@ export interface Event {
|
|||||||
};
|
};
|
||||||
startTime: string;
|
startTime: string;
|
||||||
endTime?: string;
|
endTime?: string;
|
||||||
|
UTCOffset?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user