VirtualBox

Ignore:
Timestamp:
Mar 16, 2015 10:29:40 AM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: in SnapshotAgeFormat(), call QDateTime::currentDateTime() only once and be prepared against a wrong host time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp

    r52730 r54774  
    207207        /* Age: [date time|%1d ago|%1h ago|%1min ago|%1sec ago] */
    208208        SnapshotAgeFormat ageFormat;
    209         if (mTimestamp.daysTo (QDateTime::currentDateTime()) > 30)
    210         {
    211             age = VBoxSnapshotsWgt::tr (" (%1)").arg (mTimestamp.toString (Qt::LocalDate));
     209        QDateTime now = QDateTime::currentDateTime();
     210        QDateTime then = mTimestamp;
     211        if (then > now)
     212            then = now; /* can happen if the host time is wrong */
     213        if (then.daysTo (now) > 30)
     214        {
     215            age = VBoxSnapshotsWgt::tr (" (%1)").arg (then.toString (Qt::LocalDate));
    212216            ageFormat = AgeMax;
    213217        }
    214         else if (mTimestamp.secsTo (QDateTime::currentDateTime()) > 60 * 60 * 24)
    215         {
    216             age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::daysToString(mTimestamp.secsTo (QDateTime::currentDateTime()) / 60 / 60 / 24));
     218        else if (then.secsTo (now) > 60 * 60 * 24)
     219        {
     220            age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::daysToString(then.secsTo (now) / 60 / 60 / 24));
    217221            ageFormat = AgeInDays;
    218222        }
    219         else if (mTimestamp.secsTo (QDateTime::currentDateTime()) > 60 * 60)
    220         {
    221             age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::hoursToString(mTimestamp.secsTo (QDateTime::currentDateTime()) / 60 / 60));
     223        else if (then.secsTo (now) > 60 * 60)
     224        {
     225            age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::hoursToString(then.secsTo (now) / 60 / 60));
    222226            ageFormat = AgeInHours;
    223227        }
    224         else if (mTimestamp.secsTo (QDateTime::currentDateTime()) > 60)
    225         {
    226             age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::minutesToString(mTimestamp.secsTo (QDateTime::currentDateTime()) / 60));
     228        else if (then.secsTo (now) > 60)
     229        {
     230            age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::minutesToString(then.secsTo (now) / 60));
    227231            ageFormat = AgeInMinutes;
    228232        }
    229233        else
    230234        {
    231             age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::secondsToString(mTimestamp.secsTo (QDateTime::currentDateTime())));
     235            age = VBoxSnapshotsWgt::tr (" (%1 ago)").arg(VBoxGlobal::secondsToString(then.secsTo (now)));
    232236            ageFormat = AgeInSeconds;
    233237        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette