shift start dateTime in order to have endDateTime and startDateTime on Work time
-
Given the duration of an event, i want to return the start time and end time which allow me to have the event start and end between 2 hours. For example let's assume my event start on 03/02/2020 03:12 a.m with the duration of 890280 s. It should end on 12/03/2020 11:48 p.m. I want to adjust the end in order to have both startTime and endTime between let's say 9:00 a.m and 03:00 p.m
Can anyone help pls? This is what i did but it doesn't work:
QDateTime Planning::calculateEndDate(QDateTime &startDateTime, qint64 duration) { QDateTime endDateTime; QTime dayStart=QTime::fromString(startHour(),"hh:mm"); QTime dayEnd=QTime::fromString(endHour(),"hh:mm"); qint64 workTimePerDay=dayStart.secsTo(dayEnd); if(duration <= startDateTime.time().secsTo(dayEnd)){ endDateTime=startDateTime.addSecs(duration); return endDateTime; } else{ endDateTime=startDateTime.addSecs(duration); if(isonWorkTime(endDateTime) && isWeekDay(endDateTime)){ return endDateTime; } else if(!isonWorkTime(endDateTime) && isWeekDay(endDateTime)){ } } }
I calculate the worktime per day. If it is inferior to the remaining time in the workDay we add it. If not we calculate by adding the duration. If the endDate is in workDays and is not on week-end, we have the good result. If not, i don't know what to do to shift the start in order to have both start and end on worktime.
-
Hi,
If the end falls during a break day, compute the time between that day and the text working day and then shift your start day.
By the way, you might want to correct your thread title, it's missing an f in the first word and makes it a little bit out of context ;-)
-
@SGaist said in shit start dateTime in order to have endDateTime and startDateTime on Work time:
By the way, you might want to correct your thread title, it's missing an f in the first word and makes it a little bit out of context ;-)
Fixed that - it burned my eyes ;)