Compare commits
1 Commits
master
...
date-field
| Author | SHA1 | Date | |
|---|---|---|---|
| 63b8f4f656 |
@@ -6,6 +6,14 @@ const Events: CollectionConfig = {
|
||||
useAsTitle: 'name'
|
||||
},
|
||||
timestamps: false,
|
||||
hooks: {
|
||||
afterRead: [
|
||||
({ doc }) => {
|
||||
delete doc.UTCOffset;
|
||||
return doc;
|
||||
}
|
||||
]
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
@@ -37,6 +45,17 @@ const Events: CollectionConfig = {
|
||||
timeFormat: 'HH:mm',
|
||||
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',
|
||||
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;
|
||||
endTime?: string;
|
||||
UTCOffset?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user