This is a migrated thread and some comments may be shown as answers.

'End Date' to change when 'Start Date' changes

4 Answers 98 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 07 Oct 2010, 02:53 PM
I have followed the example on how to change the End Date when the Start Date changes and it works great.

However, when the Start Time is changed, I would like to achieve the following:

  • I need the End Time to change, but I'd like it to change by a pre-defined amount of time (e.g. 1 hour 30 mins, from a TimeSpan in the code behind) added on to the Start Time. How can I do this?

Regards,
Anthony

4 Answers, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 08 Oct 2010, 09:37 AM
Getting the times to change was as simple as copying the example, but changing RadDatePicker to RadTimePicker and replacing "StartDate" and "EndDate" for "StartTime" and "EndTime" in the javascript code.

Now it is just a case of getting the EndTime to change to the StartTime plus the duration of the appointment.

Javascript is certainly not my forte, so if anyone can help me convert a string: "01:45:00" (hh:mm:ss) into a format that may be added to the start time such as below:

var duration = "01:45:00";
 
// convert the string to a date/duration
 
endDatePicker.set_selectedDate(sender.get_selectedDate() + duration);

... that would be great.

Thanks
0
Accepted
Veronica
Telerik team
answered on 11 Oct 2010, 04:33 PM
Hi Anthony,

Yes, the help topic is a part of the solution. Here's the javascript code to add the duration:

function changeEndTime(sender, e) {
                var endTimePickerID = sender.get_id().replace("StartTime", "EndTime");
                var endTimePicker = $find(endTimePickerID);
                var duration = "01:45:00";
                var durationArray = duration.split(":", 2);
                var hours = durationArray[0];
                var minutes = durationArray[1];
                var totalDurationMinutes = hours * 60 + minutes;
                endTimePicker.set_selectedDate(new Date(sender.get_selectedDate().setMinutes(sender.get_selectedDate().getMinutes() + totalDurationMinutes)));
            }

I've split the duration to get the hours and minutes separately. Then I converted all the duration to minutes (by multiplicating hours by 60) and finally added the totalDurationMinutes to the sender.SelectedDate().

Hope this helps.

Best wishes,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anthony
Top achievements
Rank 1
answered on 11 Oct 2010, 05:35 PM
Thanks for your response.

It might be worth noting that in my application, 'totalDurationMinutes' was concatenating two strings instead of adding two ints, i.e. totalDurationMinutes = 60 + 45 = 6045.

Therefore, use parseInt() on the variables and you get the correct number of minutes: 105.

function changeEndTime(sender, e) {
        var endTimePickerID = sender.get_id().replace("StartTime", "EndTime");
        var endTimePicker = $find(endTimePickerID);
        var duration = "01:45:00";
        var durationArray = duration.split(":", 2);
        var hours = parseInt(durationArray[0]);
        var minutes = parseInt(durationArray[1]);
        var totalDurationMinutes = ((hours * 60) + minutes);
        endTimePicker.set_selectedDate(new Date(sender.get_selectedDate().setMinutes(sender.get_selectedDate().getMinutes() + totalDurationMinutes)));
    }
0
Veronica
Telerik team
answered on 12 Oct 2010, 05:39 PM
Hello Anthony,

Actually my code was working without the need of the parseInt() function. However I'm glad you've found the solution.

Please note that parseInt("09") is dangerous as "09" can be considered as a number in octal numeral system. For safe conversion use parseInt("09", 10).
 
Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Scheduler
Asked by
Anthony
Top achievements
Rank 1
Answers by
Anthony
Top achievements
Rank 1
Veronica
Telerik team
Share this question
or