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. shift start dateTime in order to have endDateTime and startDateTime on Work time

shift start dateTime in order to have endDateTime and startDateTime on Work time

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 416 Views 2 Watching
  • 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 aha_1980
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ;-)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      aha_1980A B 2 Replies Last reply
      6
      • SGaistS SGaist

        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 ;-)

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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 ;)

        Qt has to stay free or it will die.

        1 Reply Last reply
        3
        • SGaistS SGaist

          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 ;-)

          B Offline
          B Offline
          Babs
          wrote on last edited by Babs
          #4
          This post is deleted!
          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