A very big problem with QDateTime



  • 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?



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



  • 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();
    }


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


  • Qt Champions 2016

    @mrdebug
    hehe Best bug ever :))


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.