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. A very big problem with QDateTime

A very big problem with QDateTime

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 924 Views 3 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by mrdebug
    #1

    Todat is Tuesday and according with Qt manual Qt::Tuesday= 2 but
    If I run
    qDebug() << "dayOfWeek" << QDateTime::currentDateTime().date().dayOfWeek();
    I obain
    dayOfWeek 3
    3 means Wednesday.

    qDebug() << "dayOfWeek" << QDateTime::currentDateTime().date().dayOfWeek();
    qDebug() << "Monday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Monday);
    qDebug() << "Tuesday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Tuesday);
    qDebug() << "Wednesday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Wednesday);
    qDebug() << "Thursday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Thursday);
    qDebug() << "Friday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Friday);
    qDebug() << "Saturday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Saturday);
    qDebug() << "Sunday" << (QDateTime::currentDateTime().date().dayOfWeek()== Qt::Sunday);
    

    And now? What can I do to set Monday as first day of the week globally?

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    1 Reply Last reply
    0
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #2

      Hi, you're sure it's Tuesday today? At least here in Sweden it's Wednesday :-)

      1 Reply Last reply
      1
      • yeckelY Offline
        yeckelY Offline
        yeckel
        wrote on last edited by
        #3

        It really seems to be working and fine. Snippets from Qt5.6 sources:

        int floordiv(int a, int b){
            return (a - (a < 0 ? b-1 : 0)) / b;
        }
        
        qint64 julianDayFromDate(int year, int month, int day)
        {
        // Adjust for no year 0
        if (year < 0)
            ++year;
        int    a = floordiv(14 - month, 12);
        qint64 y = (qint64)year + 4800 - a;
        int    m = month + 12 * a - 3;
        return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045;
        }
        
        int dayOfWeek(){
        qint64 jd = julianDayFromDate(2015,11,17);
        if (jd >= 0)
            return (jd % 7) + 1;
        else
            return ((jd + 1) % 7) + 7;
        }
        
        int main(int argc, char *argv[]){
            qDebug() << dayOfWeek();
        }
        
        1 Reply Last reply
        0
        • mrdebugM Offline
          mrdebugM Offline
          mrdebug
          wrote on last edited by
          #4

          Oh, shit!
          It's' already wednesday!!
          Sorry, I think I need an holiday.

          Need programmers to hire?
          www.labcsp.com
          www.denisgottardello.it
          GMT+1
          Skype: mrdebug

          mrjjM 1 Reply Last reply
          2
          • mrdebugM mrdebug

            Oh, shit!
            It's' already wednesday!!
            Sorry, I think I need an holiday.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @mrdebug
            hehe Best bug ever :))

            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