Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Planning app on QML problem with event date calculations



  • Hello,
    I'm working on a planning application on QML. I'm trying to write the function wich allows to calculate startTime and endTime of an event. My event must start between at a startDayTime and an endDayTime for example 9 a.m and 3 p.m.The event should not end on week-end too. The endTime must respect these conditions two.
    I'm trying to calculate the start time in order to have both start and end time to respect hour bondaries.
    This is my program:

    
    QDateTime Planning::enDateCalculProcess(QDateTime &startTime, qint64 &time,qint64 &workTime,qint64 &iraTime,QTime &startDayTime, QTime &endDayTime)
    {
        qint64 remainingTimeInStartDate= startTime.time().secsTo(endDayTime);
        if(time <= remainingTimeInStartDate){
            startTime=startTime.addSecs(time);
            return startTime.addSecs(iraTime);
        }
        else{
    
            qint64 numOfDays= time/workTime;
            qint64 remainingTime= time % workTime;
            qDebug()<<numOfDays<<"//"<<remainingTime;
            startTime=startTime.addDays(numOfDays);
            if(remainingTime > startTime.time().secsTo(endDayTime)){
                startTime=startTime.addDays(1);
                startTime.setTime(startDayTime);
                startTime=startTime.addSecs(remainingTime);
                if(!isWeekDay(startTime)){
                    QDateTime nexStart=startTime.addDays(8 -startTime.date().dayOfWeek());
                    nexStart.setTime(startDayTime);
                    startTime=nexStart.addSecs(remainingTime);
                }
            }
            else{
                startTime=startTime.addSecs(remainingTime);
                if(!isWeekDay(startTime)){
                    QDateTime nexStart=startTime.addDays(8 -startTime.date().dayOfWeek());
                    nexStart.setTime(startDayTime);
                    startTime=startTime.addSecs(remainingTime);
                }
            }
    
            startTime=startTime.addSecs(remainingTime);
            QDateTime endDate=startTime.addSecs(iraTime);
            return endDate;
    
        }
    }
    

    I have initially calculated the start and endTime and in case it does not match the conditions i call this function. The user select the start time and we calculate the end by adding the irraditon time to it (iraTime). We must propose a start and end to the user to respect the boundaries.
    Can anyone help pls?


Log in to reply