Fix date field to amend to timezone offset

This commit is contained in:
2022-07-24 11:46:59 +00:00
parent 53dfc26b88
commit 63b8f4f656
2 changed files with 41 additions and 1 deletions

View File

@@ -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,
},
},
] ]
}; };

View File

@@ -41,4 +41,5 @@ export interface Event {
}; };
startTime: string; startTime: string;
endTime?: string; endTime?: string;
UTCOffset?: string;
} }