Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Planning app on QML problem with event date calculations
QtWS25 Last Chance

Planning app on QML problem with event date calculations

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtimeqdatetime
1 Posts 1 Posters 235 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Babs
    wrote on last edited by Babs
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved