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. Weeks between two dates limit
Forum Updated to NodeBB v4.3 + New Features

Weeks between two dates limit

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 162 Views 1 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.
  • O Offline
    O Offline
    ollarch
    wrote on last edited by ollarch
    #1

    Hi,

    I have an application that when the user enters a date by entering the week of the year and the year, it cannot be older than N weeks (N should be 52 weeks or higher).

    Cannot find a way to go using QDate.

    Any idea?

    Thanks,

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

      Hi,

      Do you mean the editor should not allow that or the user should get a message ?

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

      1 Reply Last reply
      0
      • O ollarch

        Hi,

        I have an application that when the user enters a date by entering the week of the year and the year, it cannot be older than N weeks (N should be 52 weeks or higher).

        Cannot find a way to go using QDate.

        Any idea?

        Thanks,

        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        @ollarch said in Weeks between two dates limit:

        user enters a date by entering the week of the year and the year

        What is the date of a week? First day of that ISO week/year number combo? Last day?
        Are you defining your week number differently to ISO?

        (N should be 52 weeks or higher).

        If the intent is that the entered date is not more than a year old also consider that some years have 53 ISO weeks.

        O 1 Reply Last reply
        0
        • C ChrisW67

          @ollarch said in Weeks between two dates limit:

          user enters a date by entering the week of the year and the year

          What is the date of a week? First day of that ISO week/year number combo? Last day?
          Are you defining your week number differently to ISO?

          (N should be 52 weeks or higher).

          If the intent is that the entered date is not more than a year old also consider that some years have 53 ISO weeks.

          O Offline
          O Offline
          ollarch
          wrote on last edited by
          #4

          Hi,

          I have solved it using this approach:

          QDate qCurrentDate = QDate::currentDate();
          QDate qOldDate = qCurrentDate.addDays(-7 * m_qMaxWeeks);
          

          Then, iterating on the qOldDate adding 7 days on each iteration you can get the weekNumber and the year. Here you can check if the input weekNumber and Year is on a valid range.

          Thanks,

          JonBJ 1 Reply Last reply
          0
          • O ollarch

            Hi,

            I have solved it using this approach:

            QDate qCurrentDate = QDate::currentDate();
            QDate qOldDate = qCurrentDate.addDays(-7 * m_qMaxWeeks);
            

            Then, iterating on the qOldDate adding 7 days on each iteration you can get the weekNumber and the year. Here you can check if the input weekNumber and Year is on a valid range.

            Thanks,

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @ollarch said in Weeks between two dates limit:

            iterating on the qOldDate adding 7 days on each iteration

            I'm not quite sure what you mean here. But "iterating" up to 52/53 times to discover something about a "week number" sounds very inefficient when presumably it could be calculated with some kind of subtraction and a division by 7. Or maybe using int QDate::weekNumber() or perhaps qint64 QDate::daysTo(). Having said that, you won't notice 50 iterations if you are just validating an interactive user input so if you are happy with this or can't be bothered to improve that is OK :)

            1 Reply Last reply
            2
            • O Offline
              O Offline
              ollarch
              wrote on last edited by
              #6

              Hi,

              Maybe it can be improved thinking a little bit more.

              Think on that the user enters the week number and the year, not really a date with a day, month and year. So, the week number and year cannot be older than N weeks from current date.

              Using qint64 QDate::daysTo() maybe can help.

              Thanks,

              1 Reply Last reply
              1

              • Login

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