Discuss anything related to web development but no technical support questions

Post by lxxrxns »

Could you please explain to me or show me an example of how to set the starting time to e.g. 13:30 when someone creates a new event on a certain date? Since the start date and time are in 1 value, how do I keep the date but only change the hours and minutes? Thanks for the help!

Post by lxxrxns »

Pfew, after a lot of puzzling, I managed to get it working!

listeners : {
  eventAutoCreated (event) {
    var date = DateHelper.format(event.eventRecord.data.startDate, 'YYYY-MM-DD');
    var starttime = date + ' 13:30';
    var endtime = date + ' 14:30';
    event.eventRecord.data.startDate= DateHelper.parse(starttime, 'YYYY-MM-DD HH:mm');
    event.eventRecord.data.endDate= DateHelper.parse(endtime, 'YYYY-MM-DD HH:mm');

Probably it can be done in an easier/cleaner way, but I am no javascript expert :-P
Thanks for the help!

Post by mats »

A little cleaner, no need to set end date if your duration is 1 hour already:

listeners : {
  eventAutoCreated ({ eventRecord }) {
    const date = new Date(eventRecord.startDate);
date.setHours(13); date.setMinutes(30) eventRecord.startDate = date; } }

Post Reply